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

[PATCH 2/2] fetch: add support for HEAD update on mirrors

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 5, 2023, 01:27 UTC
Message-ID
<20230405012742.2452208-3-felipe.contreras@gmail.com>
In-Reply-To
<20230405012742.2452208-1-felipe.contreras@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/fetch.c  | 15 ++++++++++-----
 t/t5510-fetch.sh | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 7e93a1aa46..6bf147b012 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1593,12 +1593,17 @@ static void update_head(int config, const struct ref *head, const struct remote
 	if (!head || !head->symref || !remote)
 		return;
 
-	ref = apply_refspecs((struct refspec *)&remote->fetch, "refs/heads/HEAD");
-	target = apply_refspecs((struct refspec *)&remote->fetch, head->symref);
+	if (!remote->mirror) {
+		ref = apply_refspecs((struct refspec *)&remote->fetch, "refs/heads/HEAD");
+		target = apply_refspecs((struct refspec *)&remote->fetch, head->symref);
 
-	if (!ref || !target) {
-		warning(_("could not update remote head"));
-		return;
+		if (!ref || !target) {
+			warning(_("could not update remote head"));
+			return;
+		}
+	} else {
+		ref = "HEAD";
+		target = head->symref;
 	}
 
 	r = resolve_ref_unsafe(ref, 0, NULL, &flags);
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index dbeb2928ae..d3f3b24378 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -845,6 +845,24 @@ test_expect_success 'updatehead' '
 	)
 '
 
+test_expect_success 'updatehead mirror' '
+	test_when_finished "rm -rf updatehead" &&
+
+	git clone --mirror . updatehead &&
+	(
+		cd updatehead &&
+
+		git config fetch.updateHead missing &&
+		git symbolic-ref HEAD refs/heads/side &&
+		git fetch &&
+		test_cmp_symbolic_ref HEAD refs/heads/side &&
+
+		git config fetch.updateHead always &&
+		git fetch &&
+		test_cmp_symbolic_ref HEAD refs/heads/main
+	)
+'
+
 # configured prune tests
 
 set_config_tristate () {
-- 
2.40.0+fc1
Previous: Ævar Arnfjörð Bjarmason
Message 9 of 9 in “Add fetch.updateHead option”
  1. 0/2 Add fetch.updateHead optionFelipe Contreras, Apr 5, 2023
  2. 1/2 Add fetch.updateHead optionFelipe Contreras, Apr 5, 2023
  3. Ævar Arnfjörð BjarmasonApr 5, 2023
  4. Patrick SteinhardtApr 5, 2023
  5. Felipe ContrerasApr 5, 2023
  6. Ævar Arnfjörð BjarmasonApr 6, 2023
  7. Felipe ContrerasApr 7, 2023
  8. Ævar Arnfjörð BjarmasonApr 5, 2023
  9. 2/2 fetch: add support for HEAD update on mirrorsFelipe Contreras, Apr 5, 2023

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.