Method: Git::Base.root_of_worktree

Defined in:
lib/git/base.rb

.root_of_worktree(working_dir)

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/git/base.rb', line 64

def self.root_of_worktree(working_dir)
  result = working_dir
  status = nil

  git_cmd = "#{Git::Base.config.binary_path} -c core.quotePath=true -c color.ui=false rev-parse --show-toplevel 2>&1"
  result, status = Open3.capture2(git_cmd, chdir: File.expand_path(working_dir))
  result = result.chomp

  raise ArgumentError, "'#{working_dir}' is not in a git working tree" unless status.success?
  result
end