Class: GitCompound::Repository::GitCommand

Inherits:
Object
  • Object
show all
Extended by:
Logger::Debugger
Defined in:
lib/git_compound/repository/git_command.rb,
lib/git_compound/logger/debug/repository.rb

Overview

Debug messages for GitCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger::Debugger

debug_after, debug_before

Constructor Details

#initialize(cmd, args, workdir = nil) ⇒ GitCommand

Returns a new instance of GitCommand.



10
11
12
13
# File 'lib/git_compound/repository/git_command.rb', line 10

def initialize(cmd, args, workdir = nil)
  @command = "git #{cmd} #{args}"
  @workdir = workdir
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



8
9
10
# File 'lib/git_compound/repository/git_command.rb', line 8

def command
  @command
end

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/git_compound/repository/git_command.rb', line 8

def output
  @output
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/git_compound/repository/git_command.rb', line 8

def status
  @status
end

Instance Method Details

#executeObject

Raises:



22
23
24
25
26
# File 'lib/git_compound/repository/git_command.rb', line 22

def execute
  execute!
  raise GitCommandError, @output unless valid?
  @output
end

#execute!Object



15
16
17
18
19
20
# File 'lib/git_compound/repository/git_command.rb', line 15

def execute!
  path = @workdir ? @workdir : Dir.pwd
  Dir.chdir(path) { @output = `(#{@command}) 2>&1` }
  @status = $CHILD_STATUS.exitstatus
  @output.sub!(/\n\Z/, '')
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/git_compound/repository/git_command.rb', line 28

def valid?
  @status == 0
end