From patchwork Tue Dec 3 21:56:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13893005 Received: from aib29agh124.zrh1.oracleemaildelivery.com (aib29agh124.zrh1.oracleemaildelivery.com [192.29.178.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1CBE19259E for ; Tue, 3 Dec 2024 21:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263106; cv=none; b=CnQihzBQpvmC71tjYKLlNaSTILMCw+/IzNyvbj30rDfvXx2Npfqn1gcaFfEuoTt6l3p2jPmh8Ei3nvSZJdy9yCA9wO3iD1GeJIK8fsYbu3uR3QAXpjvf121SqjLBVwR31bVuYYz/HdCYcehmeQB9wrkAYOxQBMq47dkaYFbvc8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263106; c=relaxed/simple; bh=PwLmB3w/IOvV0PdqyS0iZPx8mrrHXslTG2YUb2pytA0=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=hHsSQOQVKb0BUmM9tY/8qzl3/sMSWMP2GEwjJjcNa7VidgdpMVp8ftHuWmnU0TeBT6lM7/iL6ohH2RHL0xj7DFxxxhM9gSZnkhfg9RxcYWJeDoa3v38QmDjwwM78qXjzDwAxwJq+YQVhrJlBfWb9/P0zYREaKPEkuRPtBub+OFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=SIuSKaIn; arc=none smtp.client-ip=192.29.178.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="SIuSKaIn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=yJp1fsfLBheuVdkDCxyC9owzPuorta2XcJ1D5wDF/qY=; b=SIuSKaInimTRkBhi1/ucmPqeuBkjsz3haTN/eBCcqiw3QlGUHXzTW2kcAXaXAGvqOFmSKha+VbGn OFhPQ+8MCVYwvUcZ0h8eBtLtApPrcdIMchxhS73InC4DpSxDFK99jIN6uk5nAflENaWICjADY6Tz A3AIBC7THsYaiCYJXJjHnXNQnb4SaGPAoecS/hKi4n1lnEqY0fxUoSQR9rJrDFJV0adlTVqm3Gvk riwJrYa0TDA2Gmg5XiKKwYAcrlOYTOAnCM9tsi855GgRiG6AHfoLXTjkMAH7jVfk1oBQTUvqJN/i 4SznyKSC9x2+Xz5MZBmhgNvRZxaYm5m1rqF1pQ== Received: by omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241107 64bit (built Nov 7 2024)) with ESMTPS id <0SNX00C0WUD39AF0@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Tue, 03 Dec 2024 21:58:15 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Junio C Hamano , Bence Ferdinandy Subject: [RFC PATCH v1 1/2] fetch set_head: add warn-if-not-$branch option Date: Tue, 3 Dec 2024 22:56:47 +0100 Message-id: <20241203215713.135068-2-bence@ferdinandy.com> In-reply-to: <20241203215713.135068-1-bence@ferdinandy.com> References: <20241203215713.135068-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFqDQYZm1jFPCZW4D1Fmo9zRzjP+gpQNTqhKjfCq3HsU0+faZzMQLQkVEsEkPva 9litAjVwA0PDvpxXpARVDFf+FhVB+PGHqivSIFTNtjeT2NUDb0P/FbzrHK/dYO/T hyzx1Tza+FHqL0JKwtX0TpJ+oGw2aCQFvu594mo3vWKjVdund16SR3xUl6ibSdIU wSBYaUZpcgj2IKUvSTtz0rTGzvOtoah5rcZEGn9aKSxVHgD4EgQV9bPzARRQD27g KlpFHCrZODJvbW/oGho9vMXMsxQ3gJTNYNHFtz7mNJ8VCMvGRkqBo5+/5WOeU9cg /ERjdyCHpnyanePcvonVgTm4fKPv9Dd6Dhq9LeWRNS4Hytdyt1TV4JDzpBVb2bz5 qhTlb0DTgkRTtQo6tOVlmb1h53KfwogBXBKlmPnK+RYiPjANg/xhENtL/rni+11F zjmxeUGxVmexONDlSBsjBu0M1dFhzMiuSLa7/r2hVUw2wHDFec2nJhE= Currently if we want to have a remote/HEAD locally that is different from the one on the remote, but we still want to get a warning if remote changes HEAD, our only option is to have an indiscriminate warning with "follow_remote_head" set to "warn". Add a new option "warn-if-not-$branch", where $branch is a branch name we do not wish to get a warning about. If the remote HEAD is $branch do not warn, otherwise, behave as "warn". E.g. let's assume, that our remote origin has HEAD set to "master", but locally we have "git remote set-head origin seen". Setting 'remote.origin.followRemoteHEAD = "warn"' will always print a warning, even though the remote has not changed HEAD from "master". Setting 'remote.origin.followRemoteHEAD = "warn-if-not-master" will squelch the warning message, unless the remote changes HEAD from "master". Note, that should the remote change HEAD to "seen" (which we have locally), there will still be no warning. Improve the advice message in report_set_head to also include silencing the warning message with "warn-if-not-$branch". Signed-off-by: Bence Ferdinandy --- builtin/fetch.c | 26 ++++++++++++++++++------- remote.c | 5 +++++ remote.h | 6 ++++-- t/t5510-fetch.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 75 insertions(+), 11 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 88c5c5d781..fd7f3694cc 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1579,6 +1579,15 @@ static const char *strip_refshead(const char *name){ return name; } +static void set_head_advice_msg(const char *remote, const char *head_name) { + + printf("Run 'git remote set-head %s %s' to follow the change, or\n" + "'git config set remote.%s.warn-if-not-%s' to disable this warning\n" + "until the remote changes HEAD again.\n", + remote, head_name, remote, head_name); + +} + static void report_set_head(const char *remote, const char *head_name, struct strbuf *buf_prev, int updateres) { struct strbuf buf_prefix = STRBUF_INIT; @@ -1590,20 +1599,19 @@ static void report_set_head(const char *remote, const char *head_name, if (prev_head && strcmp(prev_head, head_name)) { printf("'HEAD' at '%s' is '%s', but we have '%s' locally.\n", remote, head_name, prev_head); - printf("Run 'git remote set-head %s %s' to follow the change.\n", - remote, head_name); + set_head_advice_msg(remote, head_name); } else if (updateres && buf_prev->len) { printf("'HEAD' at '%s' is '%s', " "but we have a detached HEAD pointing to '%s' locally.\n", remote, head_name, buf_prev->buf); - printf("Run 'git remote set-head %s %s' to follow the change.\n", - remote, head_name); + set_head_advice_msg(remote, head_name); } strbuf_release(&buf_prefix); } -static int set_head(const struct ref *remote_refs, int follow_remote_head) +static int set_head(const struct ref *remote_refs, int follow_remote_head, + const char *no_warn_branch) { int result = 0, create_only, is_bare, was_detached; struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT, @@ -1660,7 +1668,10 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head) result = 1; goto cleanup; } - if (follow_remote_head == FOLLOW_REMOTE_WARN && verbosity >= 0) + if ((follow_remote_head == FOLLOW_REMOTE_WARN || + (follow_remote_head == FOLLOW_REMOTE_WARN_IF_NOT_BRANCH && + strcmp(no_warn_branch, head_name)) + ) && verbosity >= 0) report_set_head(remote, head_name, &b_local_head, was_detached); cleanup: @@ -1889,7 +1900,8 @@ static int do_fetch(struct transport *transport, "you need to specify exactly one branch with the --set-upstream option")); } } - if (set_head(remote_refs, transport->remote->follow_remote_head)) + if (set_head(remote_refs, transport->remote->follow_remote_head, + transport->remote->no_warn_branch)) ; /* * Way too many cases where this can go wrong diff --git a/remote.c b/remote.c index 0b18840d43..f0e1b1b76a 100644 --- a/remote.c +++ b/remote.c @@ -515,6 +515,7 @@ static int handle_config(const char *key, const char *value, return parse_transport_option(key, value, &remote->server_options); } else if (!strcmp(subkey, "followremotehead")) { + const char *no_warn_branch; if (!strcmp(value, "never")) remote->follow_remote_head = FOLLOW_REMOTE_NEVER; else if (!strcmp(value, "create")) @@ -523,6 +524,10 @@ static int handle_config(const char *key, const char *value, remote->follow_remote_head = FOLLOW_REMOTE_WARN; else if (!strcmp(value, "always")) remote->follow_remote_head = FOLLOW_REMOTE_ALWAYS; + else if (skip_prefix(value, "warn-if-not-", &no_warn_branch)) { + remote->follow_remote_head = FOLLOW_REMOTE_WARN_IF_NOT_BRANCH; + remote->no_warn_branch = no_warn_branch; + } } return 0; } diff --git a/remote.h b/remote.h index 184b35653d..75be3977ba 100644 --- a/remote.h +++ b/remote.h @@ -62,8 +62,9 @@ struct remote_state *remote_state_new(void); enum follow_remote_head_settings { FOLLOW_REMOTE_NEVER = -1, FOLLOW_REMOTE_CREATE = 0, - FOLLOW_REMOTE_WARN = 1, - FOLLOW_REMOTE_ALWAYS = 2, + FOLLOW_REMOTE_WARN_IF_NOT_BRANCH = 1, + FOLLOW_REMOTE_WARN = 2, + FOLLOW_REMOTE_ALWAYS = 3, }; struct remote { @@ -116,6 +117,7 @@ struct remote { struct string_list server_options; enum follow_remote_head_settings follow_remote_head; + const char *no_warn_branch; }; /** diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 2467027d34..be0c60be2c 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -124,7 +124,9 @@ test_expect_success "fetch test followRemoteHEAD warn no change" ' git fetch >output && echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \ "but we have ${SQ}other${SQ} locally." >expect && - echo "Run ${SQ}git remote set-head origin main${SQ} to follow the change." >>expect && + echo "Run ${SQ}git remote set-head origin main${SQ} to follow the change, or" >>expect && + echo "${SQ}git config set remote.origin.warn-if-not-main${SQ} to disable this warning" >>expect && + echo "until the remote changes HEAD again." >>expect && test_cmp expect output && head=$(git rev-parse refs/remotes/origin/HEAD) && branch=$(git rev-parse refs/remotes/origin/other) && @@ -161,7 +163,9 @@ test_expect_success "fetch test followRemoteHEAD warn detached" ' echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \ "but we have a detached HEAD pointing to" \ "${SQ}${HEAD}${SQ} locally." >expect && - echo "Run ${SQ}git remote set-head origin main${SQ} to follow the change." >>expect && + echo "Run ${SQ}git remote set-head origin main${SQ} to follow the change, or" >>expect && + echo "${SQ}git config set remote.origin.warn-if-not-main${SQ} to disable this warning" >>expect && + echo "until the remote changes HEAD again." >>expect && test_cmp expect output ) ' @@ -184,6 +188,47 @@ test_expect_success "fetch test followRemoteHEAD warn quiet" ' ) ' +test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is same" ' + test_when_finished "git config unset remote.origin.followRemoteHEAD" && + ( + cd "$D" && + cd two && + git rev-parse --verify refs/remotes/origin/other && + git remote set-head origin other && + git rev-parse --verify refs/remotes/origin/HEAD && + git rev-parse --verify refs/remotes/origin/main && + git config set remote.origin.followRemoteHEAD "warn-if-not-main" && + output=$(git fetch) && + test "z" = "z$output" && + head=$(git rev-parse refs/remotes/origin/HEAD) && + branch=$(git rev-parse refs/remotes/origin/other) && + test "z$head" = "z$branch" + ) +' + +test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is different" ' + test_when_finished "git config unset remote.origin.followRemoteHEAD" && + ( + cd "$D" && + cd two && + git rev-parse --verify refs/remotes/origin/other && + git remote set-head origin other && + git rev-parse --verify refs/remotes/origin/HEAD && + git rev-parse --verify refs/remotes/origin/main && + git config set remote.origin.followRemoteHEAD "warn-if-not-some/different-branch" && + git fetch >output && + echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \ + "but we have ${SQ}other${SQ} locally." >expect && + echo "Run ${SQ}git remote set-head origin main${SQ} to follow the change, or" >>expect && + echo "${SQ}git config set remote.origin.warn-if-not-main${SQ} to disable this warning" >>expect && + echo "until the remote changes HEAD again." >>expect && + test_cmp expect output && + head=$(git rev-parse refs/remotes/origin/HEAD) && + branch=$(git rev-parse refs/remotes/origin/other) && + test "z$head" = "z$branch" + ) +' + test_expect_success "fetch test followRemoteHEAD always" ' test_when_finished "git config unset remote.origin.followRemoteHEAD" && ( From patchwork Tue Dec 3 21:56:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13893018 Received: from aib29agh124.zrh1.oracleemaildelivery.com (aib29agh124.zrh1.oracleemaildelivery.com [192.29.178.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D860718A6A3 for ; Tue, 3 Dec 2024 22:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263212; cv=none; b=Xl7xOjsgo/EDNLW3tMMEChwtCjVk56NghPHXPRxQRZOxgRfo6aEQfheB1gj4GV2WWVOnkG/tUSNTB099VkX+JoI8V0c1ra1U4H1pZ7ydGkiV3Cby1NbGU3sjeeCmuLDICP+9cpI/r/i5MgastFXlBipK1f+d7oeGeLo6RRBZMzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733263212; c=relaxed/simple; bh=XliBWzp994y5BVWHeqiHVSu7T0AOUvo+moy4aA/pjMI=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=IYdwlTIyPCjl1nAJTOJiY2PiKlgKZwxNb4wt8xJ1QLED1XC/8fJFG3YuXdCK5Cs+w0XkGdEm+xTveFQ/8ISeFNrV83e9LO73SFyjAf3Dj9svfTwD9iUHyghzqEHGEn888YTIXzxR3kpmPBtK7zLr3XrQIu/0AvPchrTNvxYPmrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=TRK3q7et; arc=none smtp.client-ip=192.29.178.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="TRK3q7et" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=Jz4Uv1r1bcshYGpi7FekFxCDG6uq3CW9FdFEh4m2yqg=; b=TRK3q7etGFZZcxYJvquftlOxeHgFO5ZrGUM9TwrOhjwlK007xPs45wi+WawLXtOij+0aqi5cmE/J OzQk5SOA2c13CauTC4Hu8idmtU0nw0eYy+nxqqNsrn3Mgo85DLzlrSmQ6406wDazUBclFFvrE6UF I8eW9IyBF9HodRFU1I4Uf0OiY8LrDEmBvp2tx839hBnfLNV2SD7YOkwXSdd+Gouk819LeBSqD5r0 uvQK4Zk/Tj1O7JwdVDazW9/RmTqk3gZd5X2lz0VUfSiJsqJoqCUq+EZwixnyEldT2xHbbUBGubBm SZNmc0JLk4xJjTT44IjGgI1l7fmQMJLkplsowg== Received: by omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241107 64bit (built Nov 7 2024)) with ESMTPS id <0SNX00C4UUG79AF0@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Tue, 03 Dec 2024 22:00:07 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: phillip.wood@dunelm.org.uk, =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , karthik.188@gmail.com, Taylor Blau , Patrick Steinhardt , Junio C Hamano , Bence Ferdinandy Subject: [RFC PATCH v1 2/2] remote set-head: set followRemoteHEAD to "warn" if "always" Date: Tue, 3 Dec 2024 22:56:48 +0100 Message-id: <20241203215713.135068-3-bence@ferdinandy.com> In-reply-to: <20241203215713.135068-1-bence@ferdinandy.com> References: <20241203215713.135068-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAFqDQYZm1jFPCZW4D1Fmo9zRzjP+gpQNTqhKjfCq3HsU0+faZzMQLQkVEsEkPva 9litAjVwA0PDvpxXpASiDFf+FhVB+PGHqitjxVEjeu3zMgoLql/zwehLlh/zbL4+ ReC0AjfXHTHy6ruwssALnjHwb+i7zM6Qr9dWmaD0Jmsk0uOQhjT2VYL5uJbHGP4/ UH2pyI5b4JjfxS0LFX0o9L+d8GBo2Y0R7uxF5aTFJtXdnq2O8lBPUu5XsDYDrBu+ OkABtbPaMgo6fPXbwj7lg+4H7ABcKt6cmW1jqWtkVOTOXdmVj3fzAuqDvdLoM0x3 LKjy9rRhYEgXXJ4jfijQf5f12fhi2Ypr3VqWXOch2CFJDhzpXUXdKZ/hoeF0IvDq r/2IHQCjTus1RhGF7LzLnPrF9TJVHDjXfhAYDYw4usPTh6a7It4/QOlpZeh6PE6S x4MrNgPVvEO1xAGPqF0TgRy0VsS0r7BbB+DC2doOzvjKIgdtaYqiIYA= When running "remote set-head" manually it is unlikely, that the user would actually like to have "fetch" always update the remote/HEAD. On the contrary, it is more likely, that the user would expect remote/HEAD to stay the way they manually set it, and just forgot about having "followRemoteHEAD" set to "always". When "followRemoteHEAD" is set to "always" make running "remote set-head" change the config to "warn". Signed-off-by: Bence Ferdinandy --- builtin/remote.c | 12 +++++++++++- t/t5505-remote.sh | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/builtin/remote.c b/builtin/remote.c index 4a8b2ef678..9a30c17724 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1433,6 +1433,7 @@ static int set_head(int argc, const char **argv, const char *prefix) b_local_head = STRBUF_INIT; char *head_name = NULL; struct ref_store *refs = get_main_ref_store(the_repository); + struct remote *remote; struct option options[] = { OPT_BOOL('a', "auto", &opt_a, @@ -1443,8 +1444,10 @@ static int set_head(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, builtin_remote_sethead_usage, 0); - if (argc) + if (argc) { strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]); + remote = remote_get(argv[0]); + } if (!opt_a && !opt_d && argc == 2) { head_name = xstrdup(argv[1]); @@ -1483,6 +1486,13 @@ static int set_head(int argc, const char **argv, const char *prefix) } if (opt_a) report_set_head_auto(argv[0], head_name, &b_local_head, was_detached); + if (remote->follow_remote_head == FOLLOW_REMOTE_ALWAYS) { + struct strbuf config_name = STRBUF_INIT; + strbuf_addf(&config_name, + "remote.%s.followremotehead", remote->name); + git_config_set(config_name.buf, "warn"); + strbuf_release(&config_name); + } cleanup: free(head_name); diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 2600add82a..76ffdb2ec9 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -505,6 +505,17 @@ test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' ) ' +test_expect_success 'set-head changes followRemoteHEAD always to warn' ' + ( + cd test && + git config set remote.origin.followRemoteHEAD "always" && + git remote set-head --auto origin && + git config get remote.origin.followRemoteHEAD >output && + echo "warn" >expect && + test_cmp expect output + ) +' + cat >test/expect <<\EOF refs/remotes/origin/side2 EOF