Skip to content

Commit 83c1cc9

Browse files
committed
Merge branch 'jk/git-pm-bare-repo-fix'
In Git 2.39, Git.pm stopped working in a bare repository, which has been corrected. * jk/git-pm-bare-repo-fix: Git.pm: use "rev-parse --absolute-git-dir" rather than perl code Git.pm: fix bare repository search with Directory option
2 parents 5d77008 + d3edb0b commit 83c1cc9

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

perl/Git.pm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ sub repository {
187187
try {
188188
# Note that "--is-bare-repository" must come first, as
189189
# --git-dir output could contain newlines.
190-
$out = $search->command([qw(rev-parse --is-bare-repository --git-dir)],
190+
$out = $search->command([qw(rev-parse --is-bare-repository --absolute-git-dir)],
191191
STDERR => 0);
192192
} catch Git::Error::Command with {
193193
throw Error::Simple("fatal: not a git repository: $opts{Directory}");
@@ -196,12 +196,12 @@ sub repository {
196196
chomp $out;
197197
my ($bare, $dir) = split /\n/, $out, 2;
198198

199-
require Cwd;
200-
if ($bare ne 'true') {
201-
require File::Spec;
202-
File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
203-
$opts{Repository} = Cwd::abs_path($dir);
199+
# We know this is an absolute path, because we used
200+
# --absolute-git-dir above.
201+
$opts{Repository} = $dir;
204202

203+
if ($bare ne 'true') {
204+
require Cwd;
205205
# If --git-dir went ok, this shouldn't die either.
206206
my $prefix = $search->command_oneline('rev-parse', '--show-prefix');
207207
$dir = Cwd::abs_path($opts{Directory}) . '/';
@@ -214,8 +214,6 @@ sub repository {
214214
$opts{WorkingCopy} = $dir;
215215
$opts{WorkingSubdir} = $prefix;
216216

217-
} else {
218-
$opts{Repository} = Cwd::abs_path($dir);
219217
}
220218

221219
delete $opts{Directory};

t/t9700-perl-git.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ test_expect_success 'set up test repository' '
4545
'
4646

4747
test_expect_success 'set up bare repository' '
48-
git init --bare bare.git
48+
git init --bare bare.git &&
49+
git -C bare.git --work-tree=. commit --allow-empty -m "bare commit"
4950
'
5051

5152
test_expect_success 'use t9700/test.pl to test Git.pm' '

t/t9700/test.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ sub adjust_dirsep {
147147
unlink $tmpfile3;
148148
chdir($abs_repo_dir);
149149

150+
# open alternate bare repo
151+
my $r4 = Git->repository(Directory => "$abs_repo_dir/bare.git");
152+
is($r4->command_oneline(qw(log --format=%s)), "bare commit",
153+
"log of bare repo works");
154+
150155
# unquoting paths
151156
is(Git::unquote_path('abc'), 'abc', 'unquote unquoted path');
152157
is(Git::unquote_path('"abc def"'), 'abc def', 'unquote simple quoted path');

0 commit comments

Comments
 (0)