From patchwork Wed Dec 4 10:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13893530 Received: from aib29agh125.zrh1.oracleemaildelivery.com (aib29agh125.zrh1.oracleemaildelivery.com [192.29.178.125]) (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 54DD94D9FB for ; Wed, 4 Dec 2024 10:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733308882; cv=none; b=uQkYJ5TweKSMIpddSKtn9rP0B3ooGMZrblnuS7ktZHWXXApNTMlOjFERGKLK1zbooiVz4izVzLmT2l1lrzoPDV4EPYQ8hIQx01hKBMBESRfeH7x9dPlXbaqSj7EBY+v6ybZsFr5GMvQLtlbNSbvVLhh+3sileRn4tLRPSDPvX4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733308882; c=relaxed/simple; bh=+Fx/atOKGw//dk8Qj0sNPFhEAX8Mmm+gjmFF79DkN3U=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=FZJO0Qnpo2Ppiwy+4SYn2pQfiCN3cjT6bnxxOOrU4fGktc1v/OjwEV5v1611JzersX8he24909mKH/1wJCo2kHJ1awhA/tBB6empkUTQPuZQNZwAU1qlz9q+lcgkOda09M1ZwjUafA2u7zkIwo52sd+blguGzv+hxQ8QwCnj/g8= 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=BK/elUMc; arc=none smtp.client-ip=192.29.178.125 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="BK/elUMc" 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=BK/elUMcqLotgApX6FZ2yctBZFKjV79+DZdpOfvF5mEhsahcypB0tFJAlVALBX29nvd3fw6deVE/ IxQ8OxW/f1FqqbD9cbvEFkNApq0zMQZpTBSjHzjUnXk3KD+1aMuDq9IPEU9arB/frQ02CNRYe8uW gemJbL8E6Ggj+LHh2EsudaRmI+t98T7s9BKokeDum0UFuuIcBlNc5f7SJ6Rmw6F5GbrJX201E6Ks ulXEEYZBUfcmS3EXyq4hnVuShuOFTgwW1C0scZy+7iQL2qZXC/LphHeFsFdWQYNdcRjyhvch8/Tp 5X+FUoig9wdAFLIiHALatT39lOc8/RXnwBqt9g== Received: by omta-ad1-fd2-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 <0SNY00JVVTOO9P70@omta-ad1-fd2-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Wed, 04 Dec 2024 10:41:12 +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: [PATCH v2 1/3] fetch set_head: move warn advice into advise_if_enabled Date: Wed, 4 Dec 2024 11:39:24 +0100 Message-id: <20241204104003.514905-1-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: AAEMu0/xzORhNdSQ6MwQ6xLQXVfKVXNKCD9mucJxevfKRyuSNM3DpXTHkIrWEyQ0 kPNSkGx0FcuJyH8u0ZmSAmap5I2wfo6U/zR7tbx+2svWhyOagGAAaswsHbQsIMnh Gf4XT+yaQe3hokm0pttCMZC7YXoANtX+9sTgvicaplY7f2aL/AiJAb8i53Vh41Ff 2QysbiAsA38anT5yPaSy8WZRQSmKdtinXO+oyP2G8xPrGzUTtqD3Lv6CTiZPGuks dLOb6LMPP5KKBXLnchMtcceXIIxBNG6OCS/5czcaFtbpAny3UFOsv6IFIFKG49TM qESZ4vRxSR6Rm/dF1RRI7fi29a4Zo8tE1vhKW6xE1p9Xb4ReVikh4hgIsRjAkRmZ 3muAaRd/mx6i721woDKAUVi0FZX/1Fw0y6Zqm9JVTib8eW73jmVWgzTpfM76JZXC 3exDWB/Y1iuLhs2+2apXxeZ9BXOswgrZlo3VjYylvdQUwKJ4rcyCj2kG 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 Wed Dec 4 10:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13893529 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 ED4464D9FB for ; Wed, 4 Dec 2024 10:41:14 +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=1733308877; cv=none; b=Oe0bqWGGJIEzSej/6deDTrJ3AaFkyhhiSy07vYFPZsBPmXsqexTgbckAsmUMjA3h3g7N3LfQgLh63kOsEl68Pzm1pHJ7jzV7+QtT/Cdi78oJ1FgOzsLE25CXYGkG5Z/f/TV9yoyE12k+haSbxVay9L0zbJ9dWKnJpj+HRv5Zfwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733308877; c=relaxed/simple; bh=i7H2lX2+6eThK7UUHDOXCL/NbuzUMRj/bfbr+s2htDg=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=jBgEdcRIWidX9OKBdJKpdfuEe4GOkQKnEnH8sQ0zTpx0Pe/Z91imrN03LvVi+uuUh6vbHZKx57fGmye9dAayogx768fbKefKT6k25A9pXMP5QoIiE3kOj0WkjR26+/ziy2IZc9I5YcG/9v3L3sbBa96ycb+dTxmF7ptIkf79v74= 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=lcHhLQfa; 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="lcHhLQfa" 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=/JTIOmGvcUsoY6twrH6GgHwIKtbRAsZd/0at70FsO5M=; b=lcHhLQfannNd/ry+3juZpKsEBaJsnaPAlOIZh7CWdTmSAf2TMWsF9DX707ItDw2m5pY/KeE0xC/r zhULAEeDKhCn1fZci78wZ561kcvRwwYl7naW+yZMOrhUDz2TQMzhYB1sjLdmfbGY/RodxwO90Opm SSxhk+EYi1MNSCwqzrE1OazWMr3+oIUG6zCNJ/AlvLA8zd13Vdu7Ua88KCy32KpkyDpRf4C5EVMM al8m5kVgjweYOLtpAX6+eEsxu4giFj/YgMYREFKF74R8y8NYFwicZ01JHZZIpeIPV0CqU84TXThG fUkwl3ekSlIZ7LH667mSDNu4fElC+W0sgZ1wqA== 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 <0SNY00881TOPOVF0@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Wed, 04 Dec 2024 10:41:13 +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: [PATCH v2 2/3] fetch set_head: add warn-if-not-$branch option Date: Wed, 4 Dec 2024 11:39:25 +0100 Message-id: <20241204104003.514905-2-bence@ferdinandy.com> In-reply-to: <20241204104003.514905-1-bence@ferdinandy.com> References: <20241203215713.135068-1-bence@ferdinandy.com> <20241204104003.514905-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: AAFT3u2STzDfwqqTfQV9JtTvpZc/stlRMtWIqovsFZ1gzqEvq1d9mdXL/9RJGmU1 /+rQoxRkwAtOlY+glzw60gw4SXWpYE6J3Sr8NjaAHCNscJaP4as7U8HxICWadxNo G1pRgStjF4Sl/xwA0XNR6xkjbi9AJKPimbnKKs1JcKcW2HKv0zhbMuBMkDf9Kni2 v3HWkXDws1yBCIaeDxASYGycBYUML6TiTrapQuLfryGo4aj5ZdFZNyffUTIwomNy L8rMzqjo7Xp0V6hUTUvLedW8XAzHFfqUUTSp1kcRXjbzDrEgpQK3HyVnqVNPOuf/ ciZ4N1n6ENajOFpBXOVRntvonVhpLaDFR+AOI6o76g2o31yhh0TgTRy80Zu3AiHp HPljBdB1F0Cpf4ObonE/XXC8ukV/WSzvXtI54JhhTLImHbk7M8cFuZ5S1Va7FU93 J/5yECxRM/7ew7nuFMCyNQ5ngOotsvNsv1j2tE01vlvwv0mSd4j0cm1N 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 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..5c9915b836 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" && + 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 && + 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 Wed Dec 4 10:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13893531 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 A2E112B9B7 for ; Wed, 4 Dec 2024 10:41:49 +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=1733308911; cv=none; b=QiCVV7/QklwGHrBln0565d08Htr8DDzcedgINnFn1wj7fidObIz28Tu/3dzTuzK7qK7qVV+gsCEzo2NlSvJ0/qWF6BVQIBDC6CR9DGN9yzLMPnbqEhfApNvaS5X8aC1hFecWLYIrbpC4aJxNYuMvIYLpEn6Vh3RMZz/TglgvUoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733308911; c=relaxed/simple; bh=cwlyVnOSiYUGHIGlxRZNhD3B5XLGtWr7XqbqUdxDIgA=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=hgOraO+IP7jqxmHZjj0r+IsdCkUH9IM/L9ss5SU5OFw/Y2UDISkHpUFYi5g7xiCDz1RYBbtfRzb/Z8bzb3acKLsnSWY4ql2qoQQcpUSGOyRTP307Er6XY3MYnVwgINMpy2UBcknYCw1ZNVCEGTQkFBvjeItA6ZHf+ZCm3jcDXao= 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=L3Jnh7KF; 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="L3Jnh7KF" 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=PciC9mmZNlrYxuiKqa48QI+ewG4o10srXW47Xulh80k=; b=L3Jnh7KFd2FdMaZCY59ahgP9A4zQEsohRIlbT/cYN4XV9qrGHc87Eu5wFfnWBUrvSFgaOrMK/0// cV/GwQRtSWgYFCoiZnqSugl/kQAys3e3GSpfbyCUHNNIy4fyVlJTTSHgRHi0gxm/hiHquqfRmv/6 wF9Sic/MSUAcUBEAaM9Qz3QfnWfUysTwstb7wbJDmDZzvTWLSrziS7EA4WPTYriWelMoWAMXl8G3 P9jepkk9xkLISPbPpe3dbwK1tGdoqRdIUcOxSrncce71fMs7Dk8AFO/RV7mCzItfxkz/BN4kW8Mm DOE3VXL0h8I31EUGYDr0TaPuAPttxogpOkrtUA== 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 <0SNY008DJTPNOVF0@omta-ad1-fd2-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Wed, 04 Dec 2024 10:41:47 +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: [PATCH v2 3/3] remote set-head: set followRemoteHEAD to "warn" if "always" Date: Wed, 4 Dec 2024 11:39:26 +0100 Message-id: <20241204104003.514905-3-bence@ferdinandy.com> In-reply-to: <20241204104003.514905-1-bence@ferdinandy.com> References: <20241203215713.135068-1-bence@ferdinandy.com> <20241204104003.514905-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: AAFT3u2STzDfwqqTfQV9JtTvpZc/stlRMtWIqovsFZ1gzqEvq1d9mdXL/9RJGmU1 /+rQoxRkwAtOlY+glzyP0gw4SXWpYE6J3SrIrXplDV56+ekrTc3K15p3na9qc4y6 elXrRtQKgz0fWFOovXYGz64k9BayJqrpyZO3NOmM5+fo0D7upbuG0AeIr0BY/jpn Se4HuBlVGuReVvNg7yQ4g8cJE1QdoDHshN7pPmz27iBxR10V6lrBAncicRq93M53 EzR7uOJTNGbrYOrQyOGJfo4MFs5eqMYPQSob9jdZlj6iK4rlkvnYtLixNbYEhfbS 6kqdnUI3BbVB+U1K17Xhl8GwlhBJyNvLOTvNy2i7KjerBNHxicRPUSeM7fAdJC/S Lm5M5wEq8T6Jquv8bk6zikjWJ7SQpLMar5DBBESAVx8csaA54UO11mEEfL2M3umy yAMAWmUqbNGJz4FVmq9BKmxQzkOpgIi6mY9AweDEXA6xwk2bV/wsx22a 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 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..daf70406be 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 >output && + echo "warn" >expect && + test_cmp expect output + ) +' + cat >test/expect <<\EOF refs/remotes/origin/side2 EOF