From patchwork Thu Dec 5 12:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13895181 Received: from aib29agh123.zrh1.oracleemaildelivery.com (aib29agh123.zrh1.oracleemaildelivery.com [192.29.178.123]) (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 5F765214A73 for ; Thu, 5 Dec 2024 12:18:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733401137; cv=none; b=ppiNkNvr0tpdbFeuGSTXHjH7JQ5QFI7Ner5K+jEwbxvGgmbYka5qH5FvBPCjjuPtweboqdLW3S4Wsl53er1zjaCQe5Mv8DzeajtYR67kF43hCNJOmJF6H10T+q0VVyEJpuZ0LhpHoXkMxprPbLaRXCz4faprVRXeN17EAUspB/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733401137; c=relaxed/simple; bh=+Fx/atOKGw//dk8Qj0sNPFhEAX8Mmm+gjmFF79DkN3U=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=q9x52wMqRzZNfnFPqsToh1bKPPTwkjNJMQ2u9wiZc8beupCX1Zlp5WJwK5bUCjGX/svoglnkyKM0tMmnj6A35q8vSWlNC09ALtPHMWHDylUl5NtftbQ09asu5bm3gZJFFP96QvJqV3yYXnAnbX2GeGWoU5Kxiw1jzMXBTLrna64= 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=MO/FNiWB; arc=none smtp.client-ip=192.29.178.123 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="MO/FNiWB" 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=hs7HS9x6QBl/yYFKykicezVXHC/yyJ/IKX7KvsASagU=; b=MO/FNiWBo2ASmg4HURjIhKEObpvFoHU9QkPHEJ0g0hL8tVkiOU24mhz9nkNztE56OfOUIFk/6AtX ZgDLjHGdkpqt+OR0rSiT/lhDaVHXAvjRVIjEF/0oSOa56lpBcYvl47vvNu84DmondTdkqJutidrr NlgNIBjyUsi2CutqT2D0dzv7mUuuH+kDaOOH/IVcF9U2mpI/YyGRUUP9nvNvm6uzc7F3TkFlzDX9 riiPAne6m69GCTe+ZnDZalcTa9kzUG7PsfWE9z49Y8MQ5wl+fUrQ43TLP2W46Jwo0s6jwoxwIHoo 9yku/GqngovNuzEfAlXojcuTKFC+6wTay+jh+g== Received: by omta-ad1-fd1-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20241107 64bit (built Nov 7 2024)) with ESMTPS id <0SO000BF5SVCBA20@omta-ad1-fd1-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 05 Dec 2024 12:18:48 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: Bence Ferdinandy , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Karthik Nayak , Taylor Blau , Patrick Steinhardt Subject: [PATCH v3 1/3] fetch set_head: move warn advice into advise_if_enabled Date: Thu, 5 Dec 2024 13:16:20 +0100 Message-id: <20241205121737.1181695-1-bence@ferdinandy.com> In-reply-to: <173ea521-6a2e-45aa-ae5e-4da99060cc4f@app.fastmail.com> References: <173ea521-6a2e-45aa-ae5e-4da99060cc4f@app.fastmail.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: AAENN+S17iDo31gGP2o4L5QYxGeW6jLCO1pcqz30tJPD2E33i5qJmdOLoVGP/6me 98CqK5VGhvXNvs0AHQNdK20GfZNNnk5rMru8FQX9Xeyrl97VYH4sh3FWnJJNTBGP HmPxrUxSKPTskGs7/4R0ua7PNgmKCUt2d9yYHZaZmaNd54fveX80iaj89k7KdbP4 r44Huammlob7bniXPYsh9v638b72ItAI6iQRf8Sl8/X7M49nAzWu0wuaA/T6k0JZ 3wJTfeYS7RtUkpfEjBGDhL6U4FwwtoVz5GYo86cc9yC9Xcd1+CufKLzTz0riQ4MV RS9Is1fQ++Cz85nOBUuOCAdJZ6WUKWXfx/BDPjCxlQs9tJcQUrETCdQHFNwJeNnN PW4ipLmTKhjXFBAndXANeM1YxYah6BUzWAno98VwZyikv6b1b8EHFV+otlO15kJc +QO3NdYKASOiDXiqEt6LM12yi5ZltkqxRnLZefyf1VttdHwqvZPEQToT Advice about what to do when getting a warning is typed out explicitly twice and is printed as regular output. The output is also tested for. Extract the advice message into a single place and use a wrapper function, so if later the advice is made more chatty the signature only needs to be changed in once place. Remove the testing for the advice output in the tests. Signed-off-by: Bence Ferdinandy --- Notes: v2: new patch, with the refactor moved out from the following one advice.c | 1 + advice.h | 1 + builtin/fetch.c | 17 +++++++++++++---- t/t5510-fetch.sh | 2 -- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/advice.c b/advice.c index 6b879d805c..66461fdce9 100644 --- a/advice.c +++ b/advice.c @@ -53,6 +53,7 @@ static struct { [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" }, [ADVICE_DETACHED_HEAD] = { "detachedHead" }, [ADVICE_DIVERGING] = { "diverging" }, + [ADVICE_FETCH_SET_HEAD_WARN] = { "fetchRemoteHEADWarn" }, [ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates" }, [ADVICE_FORCE_DELETE_BRANCH] = { "forceDeleteBranch" }, [ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated" }, diff --git a/advice.h b/advice.h index d7466bc0ef..cf2284ec43 100644 --- a/advice.h +++ b/advice.h @@ -20,6 +20,7 @@ enum advice_type { ADVICE_COMMIT_BEFORE_MERGE, ADVICE_DETACHED_HEAD, ADVICE_DIVERGING, + ADVICE_FETCH_SET_HEAD_WARN, ADVICE_FETCH_SHOW_FORCED_UPDATES, ADVICE_FORCE_DELETE_BRANCH, ADVICE_GRAFT_FILE_DEPRECATED, diff --git a/builtin/fetch.c b/builtin/fetch.c index 62769d1686..087beb4c92 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1579,6 +1579,17 @@ static const char *strip_refshead(const char *name){ return name; } +static void set_head_advice_msg(const char *remote, const char *head_name) +{ + const char message_advice_set_head[] = + N_("Run 'git remote set-head %s %s' to follow the change, or set\n" + "'remote.%s.followRemoteHEAD' configuration option to a different value\n" + "if you do not want to see this message."); + + advise_if_enabled(ADVICE_FETCH_SET_HEAD_WARN, _(message_advice_set_head), + remote, head_name, remote); +} + 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,15 +1601,13 @@ 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); } diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index ccb74428bc..5d7ee1b550 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -123,7 +123,6 @@ 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 && test_cmp expect output && head=$(git rev-parse refs/remotes/origin/HEAD) && branch=$(git rev-parse refs/remotes/origin/other) && @@ -160,7 +159,6 @@ 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 && test_cmp expect output ) ' From patchwork Thu Dec 5 12:16:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13895180 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 7AA81214A73 for ; Thu, 5 Dec 2024 12:18:50 +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=1733401132; cv=none; b=azypC/NdqNIi2CgE+xeuBEE8FwhswB7tsRFaHt/27uVhNV5g5BvRTb89omz5Zxuc0UJItdJhc5OmfyG1eQ8jvXmekLiq1Bt6rKzwKcO71Mw9d2kEMCztBVY5tpe06uaijg5NicFGk0rHd9b2RQslUngK7lQRX0OVYBRsfqEESSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733401132; c=relaxed/simple; bh=715ZaPAej0L1Giw0+UQ/k65E+y+cwFodapw8Ikb2FCg=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=AeRMr9hrcQJVcfVrXjTcZCk09w3QgQJN1nCwJ7xixWRLQN/UF4sBiFcKE8vpdssjWgz4nUkWzZLckT5ehzET5pV+FLYaf8R9kRB9yMaWNxdLu5WdYeV4yBmKw5BYeQfrTUwBH4HorQUCC+/CDAE8orwhUvPvdNikicZMjtIfqv8= 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=KCZzhIId; 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="KCZzhIId" 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=lSFjlf5lCY/tOu4SDDsdKryI8Zegteb0LBJ046zbWwQ=; b=KCZzhIId0q+h/kwYghRwnL4Cm7UB7Ft41F5yM+Mv0ajw7siq+TIBQJwslJBGpAbcCu8+Z3B7+keD rHvDor/boPb2Hvtsumn0WqWjIlpM9VYqIx0H+ZE7Y0INoMGsyMxl2YyTVQHQHsWPEuwF/r6nxH0p Fvf1IVbWCGEWHRIwDH00bxJbfuoCEzX4rcF4XUUznFV5TlVQ81hj9fUd8yj8PGHRr0shC8fnjxXs yecsChRHNGzUCBBq1IDFW4LMUK78qETsWEP18nJAG7iu8xb+xXNYT4W6PPm5K6dI/JQI9BpNdLDt vx6+q7YhHs2Rb1T/4MP8PSG7cdx0kMSKgfKQWA== 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 <0SO000D5USVCUG80@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 05 Dec 2024 12:18:48 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: Bence Ferdinandy , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Karthik Nayak , Taylor Blau , Patrick Steinhardt Subject: [PATCH v3 2/3] fetch set_head: add warn-if-not-$branch option Date: Thu, 5 Dec 2024 13:16:21 +0100 Message-id: <20241205121737.1181695-2-bence@ferdinandy.com> In-reply-to: <20241205121737.1181695-1-bence@ferdinandy.com> References: <173ea521-6a2e-45aa-ae5e-4da99060cc4f@app.fastmail.com> <20241205121737.1181695-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: AAF7auvij4z5nZj1+hXu9tMn/LZ18Pk4Ps3GFhpA0WpLphquIyAscYY4pgHTOzrh WB97q7yVo/cXdUcktolNJONQhm1W+3bEY4jVu2zZzYo45eoJsMVtS0gxN4GLad6J QuHxLsxu9JqBCy3LmRWh/us6AZyNRoC+as7PtfB+MHMvCwcTqvi9VGtaDF5ycesY sisPuAfyi0nAvvaraSB7Fb8aJvvgHQupaVQX6Sj6YpUHaL+CaKQAG7zjsGMIXd5N fua3AgH34l+d37cu2pBfkpt6gx2mbDdhlEuoIWQvqTwvoZk+0pJQSnhFZY069gUe o7RazPnmkw87uSaIqFrUoVMIfST+IC+2V6EB9vfmT9to6U9qTvG3Ebmpz0f7s9qr 7VrE3VH/hCQ/poiXIg7yWYiqWnFpLrBOwTm0Wih1R5ee/4UUopqVVgTg7oGKg2YH 4p5HgELuAXYWuqhJyBJPMU63vsjJz0UTlkIM/1a7zmzFTZwrO+E8HlyZ 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 --- Notes: v2: reuse FOLLOW_REMOTE_WARN add documentation v3: s/output/actual in tests Documentation/config/remote.txt | 8 ++++--- builtin/fetch.c | 16 +++++++++----- remote.c | 13 +++++++++-- remote.h | 1 + t/t5510-fetch.sh | 38 +++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/Documentation/config/remote.txt b/Documentation/config/remote.txt index 024f92befc..4118c219c1 100644 --- a/Documentation/config/remote.txt +++ b/Documentation/config/remote.txt @@ -106,10 +106,12 @@ remote..followRemoteHEAD:: How linkgit:git-fetch[1] should handle updates to `remotes//HEAD`. The default value is "create", which will create `remotes//HEAD` if it exists on the remote, but not locally, but will not touch an - already existing local reference. Setting to "warn" will print + already existing local reference. Setting to "warn" will print a message if the remote has a different value, than the local one and - in case there is no local reference, it behaves like "create". Setting - to "always" will silently update it to the value on the remote. + in case there is no local reference, it behaves like "create". + A variant on "warn" is "warn-if-not-$branch", which behaves like + "warn", but if `HEAD` on the remote is `$branch` it will be silent. + Setting to "always" will silently update it to the value on the remote. Finally, setting it to "never" will never change or create the local reference. + diff --git a/builtin/fetch.c b/builtin/fetch.c index 087beb4c92..b3f6793026 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1584,10 +1584,12 @@ static void set_head_advice_msg(const char *remote, const char *head_name) const char message_advice_set_head[] = N_("Run 'git remote set-head %s %s' to follow the change, or set\n" "'remote.%s.followRemoteHEAD' configuration option to a different value\n" - "if you do not want to see this message."); + "if you do not want to see this message. Specifically running\n" + "'git config set remote.%s.followRemoteHEAD %s' will disable the warning\n" + "until the remote changes HEAD to something else."); advise_if_enabled(ADVICE_FETCH_SET_HEAD_WARN, _(message_advice_set_head), - remote, head_name, remote); + remote, head_name, remote, remote, head_name); } static void report_set_head(const char *remote, const char *head_name, @@ -1612,7 +1614,8 @@ static void report_set_head(const char *remote, const char *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, @@ -1669,7 +1672,9 @@ 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 (verbosity >= 0 && + follow_remote_head == FOLLOW_REMOTE_WARN && + (!no_warn_branch || strcmp(no_warn_branch, head_name))) report_set_head(remote, head_name, &b_local_head, was_detached); cleanup: @@ -1898,7 +1903,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..4ec5d3f47b 100644 --- a/remote.c +++ b/remote.c @@ -515,14 +515,23 @@ 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")) remote->follow_remote_head = FOLLOW_REMOTE_CREATE; - else if (!strcmp(value, "warn")) + else if (!strcmp(value, "warn")) { remote->follow_remote_head = FOLLOW_REMOTE_WARN; - else if (!strcmp(value, "always")) + remote->no_warn_branch = NULL; + } else if (skip_prefix(value, "warn-if-not-", &no_warn_branch)) { + remote->follow_remote_head = FOLLOW_REMOTE_WARN; + remote->no_warn_branch = no_warn_branch; + } else if (!strcmp(value, "always")) { remote->follow_remote_head = FOLLOW_REMOTE_ALWAYS; + } else { + warning(_("unrecognized followRemoteHEAD value '%s' ignored"), + value); + } } return 0; } diff --git a/remote.h b/remote.h index 184b35653d..bda10dd5c8 100644 --- a/remote.h +++ b/remote.h @@ -116,6 +116,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 5d7ee1b550..3885461ac1 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -181,6 +181,44 @@ 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" && + actual=$(git fetch) && + test "z" = "z$actual" && + 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 >actual && + echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \ + "but we have ${SQ}other${SQ} locally." >expect && + test_cmp expect actual && + 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 Thu Dec 5 12:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13895182 Received: from aib29agh122.zrh1.oracleemaildelivery.com (aib29agh122.zrh1.oracleemaildelivery.com [192.29.178.122]) (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 EA409217F24 for ; Thu, 5 Dec 2024 12:19:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733401147; cv=none; b=ikwmR1MyPVIbI72DcWCwcS0djjpH/ioCnibeKsrJCAiRJxkAwZ7c7saKbahW3X1xRTsGxbIvhNJvVrSYwzTEk1v+Jf5n/GLtvi5h9yNX9+XnSSF7ZHdwMNEFb0F10kAEC64MSQ4TkWzt7ltWZVScUkSM9+u/v1g4Rd5AhaWoY0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733401147; c=relaxed/simple; bh=ejXllhv6b0UrMN2AJWzLExCvRsRbitYjyqNcKveWVgo=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=aRMlvKztZE/CPh2lYiG3CXimZeXRjNe4lb6mscpTxHhw1FtQKOjpatPDqn0HlI9bADtjfPLTcZSVYkfSf/T7tyN/kfeBuENSr1Qfo7gOB3fBsMI8M9YzqUctjoguQIscpnZMRFBkegViok2k3d+7uk9nvgx0Y29mdOb6IGoip4E= 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=E3eaIAJn; arc=none smtp.client-ip=192.29.178.122 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="E3eaIAJn" 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=gxbcC0/kx+3f+7aT+s9vshMkp7QfT/el9w1VfvAygUo=; b=E3eaIAJnwIGZrOUszQd+FzLwjQ/QodpBUMFogVZiDTzB4imGad1kPLDh9teb+pDrD0y3zNlDjvos RbO8sLp8QhlHX/EHGzVIUbpTM2zaG1GbIJ5jcH25g5y/YYAKzhJPwfa/d4GoR6/+aQSQ6xYxj3XX RzAAMHFb/pe2nt2QfmxKXX8o4Zo658h6cSE+0fnqFYEFeeNJa64lSxsRJcdc008flAntwonK8lhF 9OZ6OHR0XIzRRJYFk46dkTaJkOwbrHows9H+bzzsHoa48AZD4HgMevYC0i68d504kb79oeMl7szK FicihFPKKSeBEDDhvxDyOT/2TmnAJsCrglp83w== Received: by omta-ad1-fd1-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 <0SO0008H6SVMO080@omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Thu, 05 Dec 2024 12:18:58 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: Bence Ferdinandy , Phillip Wood , =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Karthik Nayak , Taylor Blau , Patrick Steinhardt Subject: [PATCH v3 3/3] remote set-head: set followRemoteHEAD to "warn" if "always" Date: Thu, 5 Dec 2024 13:16:22 +0100 Message-id: <20241205121737.1181695-3-bence@ferdinandy.com> In-reply-to: <20241205121737.1181695-1-bence@ferdinandy.com> References: <173ea521-6a2e-45aa-ae5e-4da99060cc4f@app.fastmail.com> <20241205121737.1181695-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: AAF7auvij4z5nZj1+hXu9tMn/LZ18Pk4Ps3GFhpA0WpLphquIyAscYY4pgHTOzrh WB97q7yVo/cXdUcktolYJONQhm1W+3bEY4hvHiA2FySVta3bzOoy/Tb4DbmAtpJG praJPulo0BLWD5Fu+LMEQ+I3P0J4DH5v4Yf5xGn1WwpA9etQ6OhoPRHFzZqauMrA iEzWOJ+5YXzW9mgB5pcoOv+kSBURBHvzX8Vo3Kb8rcQBfjw6BPWxNvpTjA6pwu6Q 4P2speFoJIhNToV/z1ThluIahcWYvGXpnK0ZOaVoOd116hZg7XKax21Bf+NZoSiK af/M7aY8jkNH6IUnHtGUEmEdviWApBdPKOe2dG/P4+8ITGn7FQJ/55CgVegi4UkH fhFsQbwCbiQ26IY63j0ezgeZuPAJCadvkwqmSsKnzJAUS+XzBb2/GUcJumHCNEM2 xbrcIpnTqEwP0a3kKYi8FS17t3toZj8ypqZooJAKxGTHMxh14zbp6Bof 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 --- Notes: v3: s/output/actual 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 d5b81445f2..32d02ca4a0 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1438,6 +1438,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, @@ -1448,8 +1449,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]); @@ -1488,6 +1491,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 7411aa770d..519f7973e3 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -504,6 +504,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 >actual && + echo "warn" >expect && + test_cmp expect actual + ) +' + cat >test/expect <<\EOF refs/remotes/origin/side2 EOF