summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@frugalware.org>2008-10-29 01:05:27 +0100
committerJunio C Hamano <gitster@pobox.com>2008-10-30 13:50:48 -0700
commitfa58186c9ba50514b36ac5ef192cd7e0bc4d7780 (patch)
treed8d68a5bfef9f96471195a93f8c30fbe6c5debf0 /refs.c
parent569740bdd0533ef5cf032edd6233710161a35725 (diff)
downloadgit-fa58186c9ba50514b36ac5ef192cd7e0bc4d7780.tar.gz
git branch -m: forbid renaming of a symref
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/refs.c b/refs.c
index b39e6f2c2d..8a38e0822f 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;