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
This commit is contained in:
Junio C Hamano
2024-09-20 11:16:32 -07:00
3 changed files with 13 additions and 9 deletions

View File

@ -187,7 +187,7 @@ sub repository {
try {
# Note that "--is-bare-repository" must come first, as
# --git-dir output could contain newlines.
$out = $search->command([qw(rev-parse --is-bare-repository --git-dir)],
$out = $search->command([qw(rev-parse --is-bare-repository --absolute-git-dir)],
STDERR => 0);
} catch Git::Error::Command with {
throw Error::Simple("fatal: not a git repository: $opts{Directory}");
@ -196,12 +196,12 @@ sub repository {
chomp $out;
my ($bare, $dir) = split /\n/, $out, 2;
require Cwd;
if ($bare ne 'true') {
require File::Spec;
File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
$opts{Repository} = Cwd::abs_path($dir);
# We know this is an absolute path, because we used
# --absolute-git-dir above.
$opts{Repository} = $dir;
if ($bare ne 'true') {
require Cwd;
# If --git-dir went ok, this shouldn't die either.
my $prefix = $search->command_oneline('rev-parse', '--show-prefix');
$dir = Cwd::abs_path($opts{Directory}) . '/';
@ -214,8 +214,6 @@ sub repository {
$opts{WorkingCopy} = $dir;
$opts{WorkingSubdir} = $prefix;
} else {
$opts{Repository} = Cwd::abs_path($dir);
}
delete $opts{Directory};

View File

@ -45,7 +45,8 @@ test_expect_success 'set up test repository' '
'
test_expect_success 'set up bare repository' '
git init --bare bare.git
git init --bare bare.git &&
git -C bare.git --work-tree=. commit --allow-empty -m "bare commit"
'
test_expect_success 'use t9700/test.pl to test Git.pm' '

View File

@ -147,6 +147,11 @@ close TEMPFILE3;
unlink $tmpfile3;
chdir($abs_repo_dir);
# open alternate bare repo
my $r4 = Git->repository(Directory => "$abs_repo_dir/bare.git");
is($r4->command_oneline(qw(log --format=%s)), "bare commit",
"log of bare repo works");
# unquoting paths
is(Git::unquote_path('abc'), 'abc', 'unquote unquoted path');
is(Git::unquote_path('"abc def"'), 'abc def', 'unquote simple quoted path');