From: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Subject: [PATCH 4/2] remote: only update remote-tracking branch if updating refspec
Date: Sat, 10 Sep 2011 15:39:23 -0400 [thread overview]
Message-ID: <1315683563-11416-1-git-send-email-martin.von.zweigbergk@gmail.com> (raw)
In-Reply-To: <7vr53rx9r6.fsf@alter.siamese.dyndns.org>
'git remote rename' will only update the remote's fetch refspec if it
looks like a default one. If the remote has no default fetch refspec,
as in
[remote "origin"]
url = git://git.kernel.org/pub/scm/git/git.git
fetch = +refs/heads/*:refs/remotes/upstream/*
we would not update the fetch refspec and even if there is a ref
called "refs/remotes/origin/master", we should not rename it, since it
was not created by fetching from the remote.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Some questions on style:
1. Should I wrap the statement in "else" block in braces when "then"
block has braces? I couldn't find anything conclusive by looking at
existing code.
2. Is it ok (as I did) to return from the function prematurely even
though it is not an error case? This will of course make the
function more brittle when it comes to adding code at the end of
it. Would you prefer to invert the condition and put the remainder
of the function inside the "then" block? Or even to extract the
code into a new function?
builtin/remote.c | 10 +++++++---
t/t5505-remote.sh | 3 ++-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 61326cb..b25dfb4 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -625,7 +625,7 @@ static int mv(int argc, const char **argv)
old_remote_context = STRBUF_INIT;
struct string_list remote_branches = STRING_LIST_INIT_NODUP;
struct rename_info rename;
- int i;
+ int i, refspec_updated = 0;
if (argc != 3)
usage_with_options(builtin_remote_rename_usage, options);
@@ -667,12 +667,13 @@ static int mv(int argc, const char **argv)
strbuf_reset(&buf2);
strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
ptr = strstr(buf2.buf, old_remote_context.buf);
- if (ptr)
+ if (ptr) {
+ refspec_updated = 1;
strbuf_splice(&buf2,
ptr-buf2.buf + strlen(":refs/remotes/"),
strlen(rename.old), rename.new,
strlen(rename.new));
- else
+ } else
warning("Not updating non-default fetch respec\n"
"\t%s\n"
"\tPlease update the configuration manually if necessary.",
@@ -695,6 +696,9 @@ static int mv(int argc, const char **argv)
}
}
+ if (!refspec_updated)
+ return 0;
+
/*
* First remove symrefs, then rename the rest, finally create
* the new symrefs.
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 15186c8..e8af615 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -637,7 +637,8 @@ test_expect_success 'rename does not update a non-default fetch refspec' '
(cd four.one &&
git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
git remote rename origin upstream &&
- test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*")
+ test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
+ git rev-parse -q origin/master)
'
--
1.7.7.rc0.317.gd0afe
prev parent reply other threads:[~2011-09-10 19:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-02 0:50 [PATCHv2 1/2] remote: write correct fetch spec when renaming remote 'remote' Martin von Zweigbergk
2011-09-02 0:50 ` [PATCHv2 2/2] remote: "rename o foo" should not rename ref "origin/bar" Martin von Zweigbergk
2011-09-02 16:03 ` [PATCHv2 1/2] remote: write correct fetch spec when renaming remote 'remote' Jeff King
2011-09-03 15:26 ` [PATCHv2 3/2] remote rename: warn when refspec was not updated Martin von Zweigbergk
2011-09-06 22:58 ` [PATCHv2 1/2] remote: write correct fetch spec when renaming remote 'remote' Junio C Hamano
2011-09-08 1:40 ` Martin von Zweigbergk
2011-09-08 3:43 ` Junio C Hamano
2011-09-08 9:08 ` Martin von Zweigbergk
2011-09-08 16:46 ` Junio C Hamano
2011-09-10 19:39 ` Martin von Zweigbergk [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=1315683563-11416-1-git-send-email-martin.von.zweigbergk@gmail.com \
--to=martin.von.zweigbergk@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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;
as well as URLs for NNTP newsgroup(s).