rename_ref: use lstat(2) when testing for symlink
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>
Lars Hjemli committed
Nov 29, 2006 at 21:44 UTC
16c2bfbb449a90db00a46984d7dd7f735caa1d56
2 files changed
+8
-1
refs.c
+1
-1
@@ -792,7 +792,7 @@ int rename_ref(const char *oldref, const char *newref)
792
struct ref_lock *lock;
793
char msg[PATH_MAX*2 + 100];
794
struct stat loginfo;
795
- int log = !stat(git_path("logs/%s", oldref), &loginfo);
795
+ int log = !lstat(git_path("logs/%s", oldref), &loginfo);
796
797
if (S_ISLNK(loginfo.st_mode))
798
return error("reflog for %s is a symlink", oldref);
t/t3200-branch.sh
+7
@@ -104,4 +104,11 @@ test_expect_success \
104
git-branch -m s/s s &&
105
test -f .git/logs/refs/heads/s'
106
107
+test_expect_failure \
108
+ 'git-branch -m u v should fail when the reflog for u is a symlink' \
109
+ 'git-branch -l u &&
110
+ mv .git/logs/refs/heads/u real-u &&
111
+ ln -s real-u .git/logs/refs/heads/u &&
112
+ git-branch -m u v'
113
+
114
test_done