git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: Rodrigo <rodrigolive@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH 1/2] Git.pm: fix bare repository search with Directory option
Date: Fri, 13 Sep 2024 08:05:23 +0200	[thread overview]
Message-ID: <ZuPWIzzYda5aVjMa@pks.im> (raw)
In-Reply-To: <20240912223604.GA650605@coredump.intra.peff.net>

On Thu, Sep 12, 2024 at 06:36:04PM -0400, Jeff King wrote:
> diff --git a/perl/Git.pm b/perl/Git.pm
> index aebfe0c6e0..cf1ef0b32a 100644
> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -197,11 +197,11 @@ sub repository {
>  		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);
> +		require File::Spec;
> +		File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
> +		$opts{Repository} = Cwd::abs_path($dir);
>  
> +		if ($bare ne 'true') {
>  			# 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};

Makes sense. We already knew that the $dir was relative, but only
remembered to handle this in case the repository was non-bare. Now both
cases use the same code to translate the relative path to an absolute
one.

> diff --git a/t/t9700-perl-git.sh b/t/t9700-perl-git.sh
> index ccc8212d73..4431697122 100755
> --- a/t/t9700-perl-git.sh
> +++ b/t/t9700-perl-git.sh
> @@ -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' '

I didn't even know that this hack was possible. I guess the alternative
would be to use git-commit-tree(1) with the empty tree ID, but that'd
also require us to update branches manually via git-update-ref(1). So...
a bit gross, but hey, if it works...

Patrick

  reply	other threads:[~2024-09-13  6:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12 16:32 Can't use bare repositories with Git.pm Rodrigo
2024-09-12 22:34 ` [PATCH 0/2] fix " Jeff King
2024-09-12 22:36   ` [PATCH 1/2] Git.pm: fix bare repository search with Directory option Jeff King
2024-09-13  6:05     ` Patrick Steinhardt [this message]
2024-09-12 22:37   ` [PATCH 2/2] Git.pm: use "rev-parse --absolute-git-dir" rather than perl code Jeff King
2024-09-13  6:05     ` Patrick Steinhardt
2024-09-13 17:46   ` [PATCH 0/2] fix bare repositories with Git.pm Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZuPWIzzYda5aVjMa@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=rodrigolive@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).