Class: MultiRepo::GitRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/multirepo/git/git-runner.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.last_command_succeededObject

Returns the value of attribute last_command_succeeded.



9
10
11
# File 'lib/multirepo/git/git-runner.rb', line 9

def last_command_succeeded
  @last_command_succeeded
end

Class Method Details

.build_command(path, git_command) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/multirepo/git/git-runner.rb', line 22

def self.build_command(path, git_command)
  if path == "."
    # It is always better to skip -C when running git commands in the
    # current directory (especially in hooks). Doing this prevents
    # any future issues because we automatically fallback to non-"-C" for ".".
    # Fixes bug: https://www.pivotaltracker.com/story/show/94505654
    return "#{git_executable} #{git_command}"
  end
  
  full_command = "#{git_executable} -C \"#{path}\" #{git_command}"
  if Config.instance.running_git_hook
    # True fix for the -C flag issue in pre-commit hook where the status command would
    # fail to provide correct results if a pathspec was provided when performing a commit.
    # http://thread.gmane.org/gmane.comp.version-control.git/263319/focus=263323
    full_command = "sh -c 'unset $(git rev-parse --local-env-vars); #{full_command};'" 
  end
  
  return full_command
end

.git_executableObject



52
53
54
# File 'lib/multirepo/git/git-runner.rb', line 52

def self.git_executable
  Config.instance.git_executable || "git"
end

.run(path, git_command, verbosity) ⇒ Object



12
13
14
15
# File 'lib/multirepo/git/git-runner.rb', line 12

def self.run(path, git_command, verbosity)
  command = build_command(path, git_command)
  runner_popen(command, verbosity)
end

.run_as_system(path, git_command) ⇒ Object



17
18
19
20
# File 'lib/multirepo/git/git-runner.rb', line 17

def self.run_as_system(path, git_command)
  command = build_command(path, git_command)
  runner_system(command)
end

.runner_popen(full_command, verbosity) ⇒ Object



42
43
44
45
# File 'lib/multirepo/git/git-runner.rb', line 42

def self.runner_popen(full_command, verbosity)
  result, @last_command_succeeded = PopenRunner.run(full_command, verbosity)
  return result
end

.runner_system(full_command) ⇒ Object



47
48
49
50
# File 'lib/multirepo/git/git-runner.rb', line 47

def self.runner_system(full_command)
  result, @last_command_succeeded = SystemRunner.run(full_command)
  return result
end