diff options
author | Jeff King <peff@peff.net> | 2024-09-13 00:36:04 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-09-13 19:42:19 +0200 |
commit | e4b353d0a138f946b2321efa7ba9094cf747dd34 (patch) | |
tree | 2a6f267255cfec1a176b65b6c8e734035eb3b5a7 /t/t9700 | |
parent | Git 2.40.3 (diff) | |
download | git-e4b353d0a138f946b2321efa7ba9094cf747dd34.tar.xz git-e4b353d0a138f946b2321efa7ba9094cf747dd34.zip |
Git.pm: fix bare repository search with Directory option
When opening a bare repository like:
Git->repository(Directory => '/path/to/bare.git');
we will incorrectly point the repository object at the _current_
directory, not the one specified by the option.
The bug was introduced by 20da61f25f (Git.pm: trust rev-parse to find
bare repositories, 2022-10-22). Before then, we'd ask "rev-parse
--git-dir" if it was a Git repo, and if it returned anything, we'd
correctly convert that result to an absolute path using File::Spec and
Cwd::abs_path(). If it didn't, we'd guess it might be a bare repository
and find it ourselves, which was wrong (rev-parse should find even a
bare repo, and our search circumvented some of its rules).
That commit dropped most of the custom bare-repo search code in favor of
using "rev-parse --is-bare-repository" and trusting the "--git-dir" it
returned. But it mistakenly left some of the bare-repo code path in
place, which was now broken. That code calls Cwd::abs_path($dir); prior
to 20da61f25f $dir contained the "Directory" option the user passed in.
But afterwards, it contains the output of "rev-parse --git-dir". And
since our tentative rev-parse command is invoked after changing
directory, it will always be the relative path "."! So we'll end up with
the absolute path of the process's current directory, not the Directory
option the caller asked for.
So the non-bare case is correct, but the bare one is broken. Our tests
only check the non-bare one, so we didn't notice. We can fix this by
running the same absolute-path fixup code for both sides.
Helped-by: Rodrigo <rodrigolive@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t9700')
-rwxr-xr-x | t/t9700/test.pl | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/t/t9700/test.pl b/t/t9700/test.pl index 6d753708d2..72e958739e 100755 --- a/t/t9700/test.pl +++ b/t/t9700/test.pl @@ -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'); |