diff mbox series

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

Message ID 20230407023736.49190-3-felipe.contreras@gmail.com (mailing list archive)
State New, archived
Headers show
Series Add fetch.updateHead option | expand

Commit Message

Felipe Contreras April 7, 2023, 2:37 a.m. UTC
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 mbox series

Patch

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 3f7b33ba78..80fcaf79c3 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1594,12 +1594,17 @@  static void update_head(int fetch_missing, const struct ref *head,
 	if (!head || !head->symref || !remote)
 		return;
 
-	ref = apply_refspecs(&remote->fetch, "refs/heads/HEAD");
-	target = apply_refspecs(&remote->fetch, head->symref);
+	if (!remote->mirror) {
+		ref = apply_refspecs(&remote->fetch, "refs/heads/HEAD");
+		target = apply_refspecs(&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 () {