git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] clone: propagate empty remote HEAD even with other branches

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 6, 2022, 22:01 UTC
Message-ID
<xmqq5yk9hpd9.fsf@gitster.g>
In-Reply-To
<xmqqr12ygl3p.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> Jeff King <peff@peff.net> writes:
> ...
>>    For a bare clone, it won't emit any warning at all (but will still
>>    set up HEAD appropriately). That's probably fine. There's no part of
>>    the operation we were unable to perform, so any "by the way, the
>>    remote HEAD wasn't there but we pointed our HEAD to it anyway"
>>    message would be purely informational. Though perhaps one could argue
>>    the same about the current "empty repository" message in a bare
>>    clone.
>
> I am kind of surprised that the code still behaves differently
> between empty and non-empty cases.  Given the earlier decision above
> to consistently use the remote's HEAD, I would have expected that
> setting HEAD to point at an non-existent ref would be done at one
> place, instead of being done for empty and non-empty clone
> separately.  We'll find out why while reading the patch, I think.

OK, that is because we have if/else on the number of refs mapped via the refspec by wanted_peer_refs(), and setup_unborn_head is done independently in each of these if/else arms.

Show 17 quoted lines
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -1298,9 +1298,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  			if (!our_head_points_at)
>  				die(_("Remote branch %s not found in upstream %s"),
>  				    option_branch, remote_name);
> -		}
> -		else
> +		} else {
>  			our_head_points_at = remote_head_points_at;
> +			if (!our_head_points_at)
> +				setup_unborn_head(transport_ls_refs_options.unborn_head_target,
> +						  reflog_msg.buf);
> +		}
>  	}
>  	else {
>  		if (option_branch)

The following rewrite with the same behaviour may be a bit easier to follow.

Thanks.
 builtin/clone.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git c/builtin/clone.c w/builtin/clone.c
index cb7b347c5a..0b172af9e4 100644
--- c/builtin/clone.c
+++ w/builtin/clone.c
@@ -1298,11 +1298,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 			if (!our_head_points_at)
 				die(_("Remote branch %s not found in upstream %s"),
 				    option_branch, remote_name);
-		} else {
+		} else if (remote_head_points_at) {
 			our_head_points_at = remote_head_points_at;
-			if (!our_head_points_at)
-				setup_unborn_head(transport_ls_refs_options.unborn_head_target,
-						  reflog_msg.buf);
+		} else {
+			our_head_points_at = NULL;
+			setup_unborn_head(transport_ls_refs_options.unborn_head_target,
+					  reflog_msg.buf);
 		}
 	}
 	else {
Previous: Junio C HamanoNext: Jeff King
Message 6 of 21 in “cloning unborn HEAD when other branches are present”
  1. 0/3 cloning unborn HEAD when other branches are presentJeff King, Jul 6, 2022
  2. 1/3 clone: drop extra newline from warning messageJeff King, Jul 6, 2022
  3. 2/3 clone: factor out unborn head setup into its own functionJeff King, Jul 6, 2022
  4. 3/3 clone: propagate empty remote HEAD even with other branchesJeff King, Jul 6, 2022
  5. Junio C HamanoJul 6, 2022
  6. Junio C HamanoJul 6, 2022
  7. Jeff KingJul 7, 2022
  8. Junio C HamanoJul 7, 2022
  9. 0/3 cloning unborn HEAD when other branches are presentJeff King, Jul 7, 2022
  10. 1/3 clone: drop extra newline from warning messageJeff King, Jul 7, 2022
  11. 2/3 clone: propagate empty remote HEAD even with other branchesJeff King, Jul 7, 2022
  12. Junio C HamanoJul 8, 2022
  13. Jeff KingJul 8, 2022
  14. 3/3 clone: use remote branch if it matches default HEADJeff King, Jul 7, 2022
  15. Junio C HamanoJul 8, 2022
  16. Jeff KingJul 8, 2022
  17. Junio C HamanoJul 8, 2022
  18. 4/3 clone: move unborn head creation to update_head()Jeff King, Jul 11, 2022
  19. Junio C HamanoJul 11, 2022
  20. Jeff KingJul 7, 2022
  21. Jonathan TanJul 6, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.