diff options
-rw-r--r-- | refs.c | 4 | ||||
-rwxr-xr-x | t/t1410-reflog.sh | 34 |
2 files changed, 36 insertions, 2 deletions
@@ -2751,10 +2751,10 @@ int log_ref_setup(const char *refname, char *logfile, int bufsize) logfd = open(logfile, oflags, 0666); if (logfd < 0) { - if (!(oflags & O_CREAT) && errno == ENOENT) + if (!(oflags & O_CREAT) && (errno == ENOENT || errno == EISDIR)) return 0; - if ((oflags & O_CREAT) && errno == EISDIR) { + if (errno == EISDIR) { if (remove_empty_directories(logfile)) { return error("There are still logs under '%s'", logfile); diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 236b13a3ab..e4409e38df 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 |