rename_ref: use lstat(2) when testing for symlink
authorLars Hjemli <hjemli@gmail.com>
Wed, 29 Nov 2006 20:44:56 +0000 (21:44 +0100)
committerJunio C Hamano <junkio@cox.net>
Wed, 6 Dec 2006 07:50:57 +0000 (23:50 -0800)
The current check for symlinked reflogs was based on stat(2), which is
utterly embarrassing.

Fix it, and add a matching testcase.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
refs.c
t/t3200-branch.sh

diff --git a/refs.c b/refs.c
index cdedb45f00d2a9c379b5cfbf78086f8d2f9eaba1..c23561e1582980e01c827540de0e0a43bf2547d3 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -792,7 +792,7 @@ int rename_ref(const char *oldref, const char *newref)
        struct ref_lock *lock;
        char msg[PATH_MAX*2 + 100];
        struct stat loginfo;
-       int log = !stat(git_path("logs/%s", oldref), &loginfo);
+       int log = !lstat(git_path("logs/%s", oldref), &loginfo);
 
        if (S_ISLNK(loginfo.st_mode))
                return error("reflog for %s is a symlink", oldref);
index afaa8536a9342d6597e82dc8b96ad8b9becafad6..5782c30b03a7e7bb7d244d305e13e856eed40a89 100755 (executable)
@@ -104,4 +104,11 @@ test_expect_success \
         git-branch -m s/s s &&
         test -f .git/logs/refs/heads/s'
 
+test_expect_failure \
+    'git-branch -m u v should fail when the reflog for u is a symlink' \
+    'git-branch -l u &&
+     mv .git/logs/refs/heads/u real-u &&
+     ln -s real-u .git/logs/refs/heads/u &&
+     git-branch -m u v'
+
 test_done