From: Bence Ferdinandy <bence@ferdinandy.com>
To: git@vger.kernel.org
Cc: johannes.schindelin@gmx.de,
Bence Ferdinandy <bence@ferdinandy.com>,
cc@mail.ferdinandy.com,
/tmp/FUboFpyPuH/0002-set-head-do-not-update-if-there-is-no-change.patch@mail.ferdinandy.com
Subject: [RFC PATCH 2/2] set-head: do not update if there is no change
Date: Tue, 10 Sep 2024 22:24:59 +0200 [thread overview]
Message-ID: <20240910203129.2251090-3-bence@ferdinandy.com> (raw)
In-Reply-To: <20240910203129.2251090-1-bence@ferdinandy.com>
Currently, even if there is no actual change to remote/HEAD calling
remote set-head will overwrite the appropriate file and if set to --auto
will also print a message saying "remote/HEAD set to branch", which
implies something was changed. In contrast, on a nil operation e.g. pull
will clearly state that nothing was done, while fetch will not output
anything.
Change the behaviour of remote set-head so that the reference is only
updated if it actually needs to change. Since set-head --auto is
essentially a fetch-like operation, align it's behaviour with fetch and
only print output if something was actually done.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
---
builtin/remote.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 35c54dd103..e220e51b84 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1400,8 +1400,8 @@ static int show(int argc, const char **argv, const char *prefix)
static int set_head(int argc, const char **argv, const char *prefix)
{
- int i, opt_a = 0, opt_d = 0, result = 0;
- struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
+ int i, opt_a = 0, opt_d = 0, is_ref_changed = 0, result = 0;
+ struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
char *head_name = NULL;
struct option options[] = {
@@ -1440,12 +1440,14 @@ static int set_head(int argc, const char **argv, const char *prefix)
if (head_name) {
strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name);
+ refs_read_symbolic_ref(get_main_ref_store(the_repository),buf.buf,&buf3);
+ is_ref_changed = strcmp(buf2.buf,buf3.buf);
/* make sure it's valid */
if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf))
result |= error(_("Not a valid ref: %s"), buf2.buf);
- else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head"))
+ else if (is_ref_changed && refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head"))
result |= error(_("Could not setup %s"), buf.buf);
- else if (opt_a)
+ else if (opt_a && is_ref_changed)
printf("%s/HEAD set to %s\n", argv[0], head_name);
free(head_name);
}
--
2.46.0
prev parent reply other threads:[~2024-09-10 20:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 20:24 [RFC PATCH 0/2] set remote/HEAD with fetch Bence Ferdinandy
2024-09-10 20:24 ` [RFC PATCH 1/2] fetch: set-head with --set-head option Bence Ferdinandy
2024-09-11 6:54 ` Jeff King
2024-09-11 12:16 ` Bence Ferdinandy
2024-09-10 20:24 ` Bence Ferdinandy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240910203129.2251090-3-bence@ferdinandy.com \
--to=bence@ferdinandy.com \
--cc=/tmp/FUboFpyPuH/0002-set-head-do-not-update-if-there-is-no-change.patch@mail.ferdinandy.com \
--cc=cc@mail.ferdinandy.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox