git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Jonathan Tan <jonathantanmy@google.com>
Subject: Re: [PATCH v2 2/3] clone: propagate empty remote HEAD even with other branches
Date: Fri, 08 Jul 2022 08:41:47 -0700	[thread overview]
Message-ID: <xmqqedyvwr0k.fsf@gitster.g> (raw)
In-Reply-To: <Ysdy+STDIhCZU05+@coredump.intra.peff.net> (Jeff King's message of "Thu, 7 Jul 2022 19:57:45 -0400")

Jeff King <peff@peff.net> writes:

> So let's pull the HEAD setup out of this conditional entirely. This
> de-duplicates some of the code and the result is easy to follow, because
> helper functions like find_ref_by_name() do the right thing even in the
> empty-repo case (i.e., by returning NULL).

Nicely done.  The first stage becomes purely about optionally
fetching when there are some refs to fetch, and then we compute
where our HEAD should be separately.  Very clean.

> Rewritten in v2 to extract more of the logic. Bigger diff, but I think
> the end result is good. Try reading with "-w", as well.

I somehow found that the rendition with "-w" less easier to follow ;-)

> diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
> index 00ce9aec23..2b3a78b842 100755
> --- a/t/t5702-protocol-v2.sh
> +++ b/t/t5702-protocol-v2.sh
> @@ -250,6 +250,44 @@ test_expect_success 'bare clone propagates empty default branch' '
>  	grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD
>  '
>  
> +test_expect_success 'clone propagates unborn HEAD from non-empty repo' '
> +	test_when_finished "rm -rf file_unborn_parent file_unborn_child" &&
> +
> +	git init file_unborn_parent &&
> +	(
> +		cd file_unborn_parent &&
> +		git checkout -b branchwithstuff &&
> +		test_commit --no-tag stuff &&
> +		git symbolic-ref HEAD refs/heads/mydefaultbranch
> +	) &&
> +
> +	GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
> +	git -c init.defaultBranch=main -c protocol.version=2 \
> +		clone "file://$(pwd)/file_unborn_parent" \
> +		file_unborn_child 2>stderr &&
> +	grep "refs/heads/mydefaultbranch" file_unborn_child/.git/HEAD &&

We know they do not have mydefaultbranch2 branch, so this grep may
be sufficient, but peeking into the implementation detail of HEAD is
not necessary.  The kosher way is way more verbose and awkward,
though:

	git -C file_unborn_child symbolic-ref HEAD >actual &&
	echo refs/heads/mydefaultbranch >expect &&
	test_cmp actual expect &&

I dunno.

> +	grep "warning: remote HEAD refers to nonexistent ref" stderr
> +'
> +
> +test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' '
> +	test_when_finished "rm -rf file_unborn_parent file_unborn_child.git" &&
> +
> +	git init file_unborn_parent &&
> +	(
> +		cd file_unborn_parent &&
> +		git checkout -b branchwithstuff &&
> +		test_commit --no-tag stuff &&
> +		git symbolic-ref HEAD refs/heads/mydefaultbranch
> +	) &&
> +
> +	GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
> +	git -c init.defaultBranch=main -c protocol.version=2 \
> +		clone --bare "file://$(pwd)/file_unborn_parent" \
> +		file_unborn_child.git 2>stderr &&
> +	grep "refs/heads/mydefaultbranch" file_unborn_child.git/HEAD &&

Likewise.

> +	! grep "warning:" stderr
> +'
> +
>  test_expect_success 'fetch with file:// using protocol v2' '
>  	test_when_finished "rm -f log" &&

  reply	other threads:[~2022-07-08 15:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06  7:57 [PATCH 0/3] cloning unborn HEAD when other branches are present Jeff King
2022-07-06  8:00 ` [PATCH 1/3] clone: drop extra newline from warning message Jeff King
2022-07-06  8:00 ` [PATCH 2/3] clone: factor out unborn head setup into its own function Jeff King
2022-07-06  8:03 ` [PATCH 3/3] clone: propagate empty remote HEAD even with other branches Jeff King
2022-07-06 18:19   ` Junio C Hamano
2022-07-06 22:01     ` Junio C Hamano
2022-07-07 17:40       ` Jeff King
2022-07-07 18:50         ` Junio C Hamano
2022-07-07 23:54           ` [PATCH v2 0/3] cloning unborn HEAD when other branches are present Jeff King
2022-07-07 23:54             ` [PATCH v2 1/3] clone: drop extra newline from warning message Jeff King
2022-07-07 23:57             ` [PATCH v2 2/3] clone: propagate empty remote HEAD even with other branches Jeff King
2022-07-08 15:41               ` Junio C Hamano [this message]
2022-07-08 16:08                 ` Jeff King
2022-07-07 23:59             ` [PATCH v2 3/3] clone: use remote branch if it matches default HEAD Jeff King
2022-07-08 16:28               ` Junio C Hamano
2022-07-08 19:30                 ` Jeff King
2022-07-08 20:33                   ` Junio C Hamano
2022-07-11  9:21                     ` [PATCH v2 4/3] clone: move unborn head creation to update_head() Jeff King
2022-07-11 20:36                       ` Junio C Hamano
2022-07-07 17:23     ` [PATCH 3/3] clone: propagate empty remote HEAD even with other branches Jeff King
2022-07-06 18:17 ` [PATCH 0/3] cloning unborn HEAD when other branches are present Jonathan Tan

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqedyvwr0k.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).