From: Miklos Vajna <vmiklos@frugalware.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, Brandon Casey <casey@nrlssc.navy.mil>,
git@vger.kernel.org
Subject: [PATCH] git branch -m: forbid renaming of a symref
Date: Wed, 29 Oct 2008 01:05:27 +0100 [thread overview]
Message-ID: <1225238727-12399-1-git-send-email-vmiklos@frugalware.org> (raw)
In-Reply-To: <20081028234541.GY24201@genesis.frugalware.org>
There may be cases where one would really want to rename the symbolic
ref without changing its value, but "git branch -m" is not such a
use-case.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
This applies on top of 'mv/maint-branch-m-symref'.
refs.c | 29 +++++++++++++----------------
t/t3200-branch.sh | 8 ++++----
2 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/refs.c b/refs.c
index b39e6f2..8a38e08 100644
--- a/refs.c
+++ b/refs.c
@@ -964,14 +964,14 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
struct stat loginfo;
int log = !lstat(git_path("logs/%s", oldref), &loginfo);
const char *symref = NULL;
- int is_symref = 0;
if (log && S_ISLNK(loginfo.st_mode))
return error("reflog for %s is a symlink", oldref);
symref = resolve_ref(oldref, orig_sha1, 1, &flag);
if (flag & REF_ISSYMREF)
- is_symref = 1;
+ return error("refname %s is a symbolic ref, renaming it is not supported",
+ oldref);
if (!symref)
return error("refname %s not found", oldref);
@@ -1035,20 +1035,17 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
}
logmoved = log;
- if (!is_symref) {
- lock = lock_ref_sha1_basic(newref, NULL, 0, NULL);
- if (!lock) {
- error("unable to lock %s for update", newref);
- goto rollback;
- }
- lock->force_write = 1;
- hashcpy(lock->old_sha1, orig_sha1);
- if (write_ref_sha1(lock, orig_sha1, logmsg)) {
- error("unable to write current sha1 into %s", newref);
- goto rollback;
- }
- } else
- create_symref(newref, symref, logmsg);
+ lock = lock_ref_sha1_basic(newref, NULL, 0, NULL);
+ if (!lock) {
+ error("unable to lock %s for update", newref);
+ goto rollback;
+ }
+ lock->force_write = 1;
+ hashcpy(lock->old_sha1, orig_sha1);
+ if (write_ref_sha1(lock, orig_sha1, logmsg)) {
+ error("unable to write current sha1 into %s", newref);
+ goto rollback;
+ }
return 0;
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index fdeb1f5..25e9971 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -112,13 +112,13 @@ test_expect_success 'config information was renamed, too' \
"test $(git config branch.s.dummy) = Hello &&
test_must_fail git config branch.s/s/dummy"
-test_expect_success 'renaming a symref' \
+test_expect_success 'renaming a symref is not allowed' \
'
git symbolic-ref refs/heads/master2 refs/heads/master &&
- git branch -m master2 master3 &&
- git symbolic-ref refs/heads/master3 &&
+ test_must_fail git branch -m master2 master3 &&
+ git symbolic-ref refs/heads/master2 &&
test -f .git/refs/heads/master &&
- ! test -f .git/refs/heads/master2
+ ! test -f .git/refs/heads/master3
'
test_expect_success \
--
1.6.0.2
next prev parent reply other threads:[~2008-10-29 0:05 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-22 0:23 [PATCH] Implement git remote mv Miklos Vajna
2008-10-22 16:52 ` Brandon Casey
2008-10-23 1:18 ` Miklos Vajna
2008-10-23 3:52 ` Jeff King
2008-10-23 12:56 ` [PATCH] Implement git remote rename Miklos Vajna
2008-10-24 23:33 ` Junio C Hamano
2008-10-25 12:58 ` [PATCH 0/2] Fixes for git branch -m / update-ref --no-deref -d Miklos Vajna
2008-10-25 12:58 ` [PATCH 1/2] Fix git branch -m for symrefs Miklos Vajna
2008-10-25 12:58 ` [PATCH 2/2] Fix git update-ref --no-deref -d Miklos Vajna
2008-10-25 18:31 ` [PATCH 1/2] Fix git branch -m for symrefs Junio C Hamano
2008-10-26 2:33 ` [PATCH 0/3] symref rename/delete fixes Miklos Vajna
2008-10-26 2:33 ` [PATCH 1/3] Fix git branch -m for symrefs Miklos Vajna
2008-10-26 2:33 ` [PATCH 2/3] rename_ref(): handle the case when the reflog of a ref does not exist Miklos Vajna
2008-10-26 2:33 ` [PATCH 3/3] Fix git update-ref --no-deref -d Miklos Vajna
2008-10-27 5:31 ` [PATCH 0/3] symref rename/delete fixes Junio C Hamano
2008-10-27 8:50 ` Miklos Vajna
2008-10-27 19:50 ` Miklos Vajna
2008-10-27 19:50 ` [PATCH 1/3] Disallow git branch -m for symrefs Miklos Vajna
2008-10-27 19:50 ` [PATCH 2/3] rename_ref(): handle the case when the reflog of a ref does not exist Miklos Vajna
2008-10-27 19:50 ` [PATCH 3/3] Fix git update-ref --no-deref -d Miklos Vajna
2008-10-28 23:45 ` [PATCH 0/3] symref rename/delete fixes Miklos Vajna
2008-10-29 0:05 ` Miklos Vajna [this message]
2008-11-03 18:26 ` [PATCH] Implement git remote rename Miklos Vajna
2008-11-10 20:42 ` Miklos Vajna
2008-11-10 20:43 ` [PATCH 1/4] remote: add a new 'origin' variable to the struct Miklos Vajna
2008-11-10 20:43 ` [PATCH 2/4] git-remote rename: support remotes->config migration Miklos Vajna
2008-11-10 20:43 ` [PATCH 3/4] git-remote rename: support branches->config migration Miklos Vajna
2008-11-10 20:43 ` [PATCH 4/4] git-remote: document the migration feature of the rename subcommand Miklos Vajna
2008-11-12 0:49 ` [PATCH 3/4] git-remote rename: support branches->config migration Junio C Hamano
2008-11-12 2:01 ` Miklos Vajna
2008-11-12 4:22 ` Junio C Hamano
2008-11-12 17:11 ` [PATCH v2 0/4] " Miklos Vajna
2008-11-12 17:11 ` [PATCH 1/4] remote: add a new 'origin' variable to the struct Miklos Vajna
2008-11-12 17:11 ` [PATCH 2/4] git-remote rename: support remotes->config migration Miklos Vajna
2008-11-12 17:11 ` [PATCH 3/4] git-remote rename: support branches->config migration Miklos Vajna
2008-11-12 17:11 ` [PATCH 4/4] git-remote: document the migration feature of the rename subcommand Miklos Vajna
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=1225238727-12399-1-git-send-email-vmiklos@frugalware.org \
--to=vmiklos@frugalware.org \
--cc=casey@nrlssc.navy.mil \
--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).