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

Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 24, 2025, 05:56 UTC
Message-ID
<Z5Mrk02wMdABtrVZ@pks.im>
In-Reply-To
<20250112165125.130400-1-bence@ferdinandy.com>
On Sun, Jan 12, 2025 at 05:51:22PM +0100, Bence Ferdinandy wrote:
Show 14 quoted lines
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index fe2b26c74a..625d45be8b 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1925,7 +1925,8 @@ static int do_fetch(struct transport *transport,
>  		}
>  	}
>  	if (set_head(remote_refs, transport->remote->follow_remote_head,
> -		transport->remote->no_warn_branch))
> +		transport->remote->no_warn_branch,
> +		transport->remote->mirror))
>  		;
>  		/*
>  		 * Way too many cases where this can go wrong
Nit: At this point it might be sensible to simply pass in the remote
itself, which would allow for an easier callsite and less risk of
getting the order of parameters wrong.
Show 10 quoted lines
> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
> index 519f7973e3..c75cfe968f 100755
> --- a/t/t5505-remote.sh
> +++ b/t/t5505-remote.sh
> @@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '
>  	)
>  '
>  
> +test_expect_success 'non-mirror fetch does not interfere with mirror' '
> +	mkdir headnotmain &&
Nit: this can be simplified into `git init --bare -b notmain
headnotmain` so that you don't have to create an empty directory first.
Also, do we want to `test_when_finished rm -rf headnotmain` to clean up
after ourselves?
Show 23 quoted lines
> +	(
> +		cd headnotmain &&
> +		git init --bare -b notmain &&
> +		git remote add -f other ../two &&
> +		test "$(git symbolic-ref HEAD)" = "refs/heads/notmain"
> +	)
> +'
> +
>  test_expect_success 'add --mirror=fetch' '
>  	mkdir mirror-fetch &&
>  	git init -b main mirror-fetch/parent &&
> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
> index 2d9587059f..cfa63ae086 100755
> --- a/t/t5510-fetch.sh
> +++ b/t/t5510-fetch.sh
> @@ -84,6 +84,19 @@ test_expect_success "fetch test remote HEAD" '
>  	branch=$(git rev-parse refs/remotes/origin/main) &&
>  	test "z$head" = "z$branch"'
>  
> +test_expect_success "fetch test remote HEAD in bare repository" '
> +	cd "$D" &&
> +	git init --bare barerepo &&
> +	cd barerepo &&

The `cd` needs to happen in a subshell. ALso, the same comment here regarding whether we want to have `test_when_finished` to clean up state.

Show 7 quoted lines
> +	git remote add upstream ../two &&
> +	git fetch upstream &&
> +	git rev-parse --verify refs/remotes/upstream/HEAD &&
> +	git rev-parse --verify refs/remotes/upstream/main &&
> +	head=$(git rev-parse refs/remotes/upstream/HEAD) &&
> +	branch=$(git rev-parse refs/remotes/upstream/main) &&
> +	test "z$head" = "z$branch"'
The closing single-quote should be on its own line.

I see though that you simply follow existing code style, both for the call to cd(1) and for the single-quote, so these are fine. This test file could use a makeover, but that is obviously outside of the scope of this patch series.

Patrick
Previous: Junio C HamanoNext: Eric Sunshine
Message 10 of 18 in “fatal: Not a valid object name HEAD”
  1. Christian HesseJan 11, 2025
  2. Bence FerdinandyJan 12, 2025
  3. Junio C HamanoJan 13, 2025
  4. fetch set_head: fix non-mirror remotes in bare repositoriesBence Ferdinandy, Jan 12, 2025
  5. Junio C HamanoJan 23, 2025
  6. Bence FerdinandyJan 23, 2025
  7. Eric SunshineJan 23, 2025
  8. Christian HesseJan 24, 2025
  9. Junio C HamanoJan 24, 2025
  10. Patrick SteinhardtJan 24, 2025
  11. Eric SunshineJan 24, 2025
  12. Junio C HamanoJan 24, 2025
  13. Bence FerdinandyJan 26, 2025
  14. Bence FerdinandyJan 26, 2025
  15. 1/2 fetch set_head: refactor to use remote directlyBence Ferdinandy, Jan 26, 2025
  16. 2/2 fetch set_head: fix non-mirror remotes in bare repositoriesBence Ferdinandy, Jan 26, 2025
  17. Patrick SteinhardtJan 27, 2025
  18. Junio C HamanoJan 27, 2025

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.