Skip to content

Commit

Permalink
Merge branch 'jk/fetch-reflog-df-conflict'
Browse files Browse the repository at this point in the history
Corner-case bugfixes for "git fetch" around reflog handling.

* jk/fetch-reflog-df-conflict:
  ignore stale directories when checking reflog existence
  fetch: load all default config at startup
  • Loading branch information
Junio C Hamano committed Nov 6, 2014
2 parents 6b55f8b + 9233887 commit a1671dd
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
fetch_prune_config = git_config_bool(k, v);
return 0;
}
return 0;
return git_default_config(k, v, cb);
}

static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
Expand Down
4 changes: 2 additions & 2 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2962,10 +2962,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)) {
int save_errno = errno;
error("There are still logs under '%s'",
Expand Down
34 changes: 34 additions & 0 deletions t/t1410-reflog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,38 @@ test_expect_success 'checkout should not delete log for packed ref' '
test $(git reflog master | wc -l) = 4
'

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
40 changes: 40 additions & 0 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This test checks the following functionality:
* hooks
* --porcelain output format
* hiderefs
* reflogs
'

. ./test-lib.sh
Expand Down Expand Up @@ -1290,4 +1291,43 @@ test_expect_success 'pushing a tag pushes the tagged object' '
test_cmp expect actual
'

test_expect_success 'push into bare respects core.logallrefupdates' '
rm -rf dst.git &&
git init --bare dst.git &&
git -C dst.git config core.logallrefupdates true &&
# double push to test both with and without
# the actual pack transfer
git push dst.git master:one &&
echo "one@{0} push" >expect &&
git -C dst.git log -g --format="%gd %gs" one >actual &&
test_cmp expect actual &&
git push dst.git master:two &&
echo "two@{0} push" >expect &&
git -C dst.git log -g --format="%gd %gs" two >actual &&
test_cmp expect actual
'

test_expect_success 'fetch into bare respects core.logallrefupdates' '
rm -rf dst.git &&
git init --bare dst.git &&
(
cd dst.git &&
git config core.logallrefupdates true &&
# as above, we double-fetch to test both
# with and without pack transfer
git fetch .. master:one &&
echo "one@{0} fetch .. master:one: storing head" >expect &&
git log -g --format="%gd %gs" one >actual &&
test_cmp expect actual &&
git fetch .. master:two &&
echo "two@{0} fetch .. master:two: storing head" >expect &&
git log -g --format="%gd %gs" two >actual &&
test_cmp expect actual
)
'

test_done

0 comments on commit a1671dd

Please sign in to comment.