Method: Overcommit::Utils.repo_root

Defined in:
lib/overcommit/utils.rb

.repo_rootString

Returns an absolute path to the root of the repository.

We do this ourselves rather than call ‘git rev-parse –show-toplevel` to solve an issue where the .git directory might not actually be valid in tests.

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/overcommit/utils.rb', line 46

def repo_root
  @repo_root ||=
    begin
      result = execute(%w[git rev-parse --show-toplevel])
      unless result.success?
        raise Overcommit::Exceptions::InvalidGitRepo,
              'Unable to determine location of GIT_DIR. ' \
              'Not a recognizable Git repository!'
      end
      result.stdout.chomp("\n")
    end
end