summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-11-04 13:24:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-11-04 20:18:44 (GMT)
commit9233887cce8eaebd8469315622b84bd26910351f (patch)
treeb138cb977ba0b24c35b4f1f6157246d003b8373a /t
parent72549dfd5d33424fbf557b0078503687780a3a53 (diff)
downloadgit-9233887cce8eaebd8469315622b84bd26910351f.zip
git-9233887cce8eaebd8469315622b84bd26910351f.tar.gz
git-9233887cce8eaebd8469315622b84bd26910351f.tar.bz2
ignore stale directories when checking reflog existence
When we update a ref, we have two rules for whether or not we actually update the reflog: 1. If the reflog already exists, we will always append to it. 2. If log_all_ref_updates is set, we will create a new reflog file if necessary. We do the existence check by trying to open the reflog file, either with or without O_CREAT (depending on log_all_ref_updates). If it fails, then we check errno to see what happened. If we were not using O_CREAT and we got ENOENT, the file doesn't exist, and we return success (there isn't a reflog already, and we were not told to make a new one). If we get EISDIR, then there is likely a stale directory that needs to be removed (e.g., there used to be "foo/bar", it was deleted, and the directory "foo" was left. Now we want to create the ref "foo"). If O_CREAT is set, then we catch this case, try to remove the directory, and retry our open. So far so good. But if we get EISDIR and O_CREAT is not set, then we treat this as any other error, which is not right. Like ENOENT, EISDIR is an indication that we do not have a reflog, and we should silently return success (we were not told to create it). Instead, the current code reports this as an error, and we fail to update the ref at all. Note that this is relatively unlikely to happen, as you would have to have had reflogs turned on, and then later turned them off (it could also happen due to a bug in fetch, but that was fixed in the previous commit). However, it's quite easy to fix: we just need to treat EISDIR like ENOENT for the non-O_CREAT case, and silently return (note that this early return means we can also simplify the O_CREAT case). Our new tests cover both cases (O_CREAT and non-O_CREAT). The first one already worked, of course. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t1410-reflog.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 236b13a..e4409e3 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -245,4 +245,38 @@ test_expect_success 'gc.reflogexpire=false' '
'
+test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '
+ test_when_finished "git branch -d a || git branch -d a/b" &&
+
+ git branch a/b master &&
+ echo "a/b@{0} branch: Created from master" >expect &&
+ git log -g --format="%gd %gs" a/b >actual &&
+ test_cmp expect actual &&
+ git branch -d a/b &&
+
+ # now logs/refs/heads/a is a stale directory, but
+ # we should move it out of the way to create "a" reflog
+ git branch a master &&
+ echo "a@{0} branch: Created from master" >expect &&
+ git log -g --format="%gd %gs" a >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' '
+ test_when_finished "git branch -d a || git branch -d a/b" &&
+
+ git branch a/b master &&
+ echo "a/b@{0} branch: Created from master" >expect &&
+ git log -g --format="%gd %gs" a/b >actual &&
+ test_cmp expect actual &&
+ git branch -d a/b &&
+
+ # same as before, but we only create a reflog for "a" if
+ # it already exists, which it does not
+ git -c core.logallrefupdates=false branch a master &&
+ : >expect &&
+ git log -g --format="%gd %gs" a >actual &&
+ test_cmp expect actual
+'
+
test_done