Skip to content

Commit 23b8942

Browse files
Antroninsds
authored andcommitted
Fix git_dir output on Git < 2.5
Strangely enough the --common-git-dir option just returns "--git-common-dir" with git version 1.17.10 if no $GIT_COMMON_DIR defined. The only way we can get correct answer is to stick to --git-dir. As long we are running Git 2.5+ we should use --git-common-dir, otherwise we can use --git-dir.
1 parent e30583d commit 23b8942

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/overcommit/utils.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def repo_root
5959
def git_dir
6060
@git_dir ||=
6161
begin
62-
result = execute(%w[git rev-parse --git-common-dir])
62+
cmd = %w[git rev-parse]
63+
cmd << (GIT_VERSION < '2.5' ? '--git-dir' : '--git-common-dir')
64+
result = execute(cmd)
6365
unless result.success?
6466
raise Overcommit::Exceptions::InvalidGitRepo,
6567
'Unable to determine location of GIT_DIR. ' \

0 commit comments

Comments
 (0)