Skip to content

Commit a1671dd

Browse files
committed
Merge branch 'jk/fetch-reflog-df-conflict'
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
2 parents 6b55f8b + 9233887 commit a1671dd

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
6868
fetch_prune_config = git_config_bool(k, v);
6969
return 0;
7070
}
71-
return 0;
71+
return git_default_config(k, v, cb);
7272
}
7373

7474
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,10 +2962,10 @@ int log_ref_setup(const char *refname, char *logfile, int bufsize)
29622962

29632963
logfd = open(logfile, oflags, 0666);
29642964
if (logfd < 0) {
2965-
if (!(oflags & O_CREAT) && errno == ENOENT)
2965+
if (!(oflags & O_CREAT) && (errno == ENOENT || errno == EISDIR))
29662966
return 0;
29672967

2968-
if ((oflags & O_CREAT) && errno == EISDIR) {
2968+
if (errno == EISDIR) {
29692969
if (remove_empty_directories(logfile)) {
29702970
int save_errno = errno;
29712971
error("There are still logs under '%s'",

t/t1410-reflog.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,38 @@ test_expect_success 'checkout should not delete log for packed ref' '
253253
test $(git reflog master | wc -l) = 4
254254
'
255255

256+
test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '
257+
test_when_finished "git branch -d a || git branch -d a/b" &&
258+
259+
git branch a/b master &&
260+
echo "a/b@{0} branch: Created from master" >expect &&
261+
git log -g --format="%gd %gs" a/b >actual &&
262+
test_cmp expect actual &&
263+
git branch -d a/b &&
264+
265+
# now logs/refs/heads/a is a stale directory, but
266+
# we should move it out of the way to create "a" reflog
267+
git branch a master &&
268+
echo "a@{0} branch: Created from master" >expect &&
269+
git log -g --format="%gd %gs" a >actual &&
270+
test_cmp expect actual
271+
'
272+
273+
test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' '
274+
test_when_finished "git branch -d a || git branch -d a/b" &&
275+
276+
git branch a/b master &&
277+
echo "a/b@{0} branch: Created from master" >expect &&
278+
git log -g --format="%gd %gs" a/b >actual &&
279+
test_cmp expect actual &&
280+
git branch -d a/b &&
281+
282+
# same as before, but we only create a reflog for "a" if
283+
# it already exists, which it does not
284+
git -c core.logallrefupdates=false branch a master &&
285+
: >expect &&
286+
git log -g --format="%gd %gs" a >actual &&
287+
test_cmp expect actual
288+
'
289+
256290
test_done

t/t5516-fetch-push.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This test checks the following functionality:
1111
* hooks
1212
* --porcelain output format
1313
* hiderefs
14+
* reflogs
1415
'
1516

1617
. ./test-lib.sh
@@ -1290,4 +1291,43 @@ test_expect_success 'pushing a tag pushes the tagged object' '
12901291
test_cmp expect actual
12911292
'
12921293

1294+
test_expect_success 'push into bare respects core.logallrefupdates' '
1295+
rm -rf dst.git &&
1296+
git init --bare dst.git &&
1297+
git -C dst.git config core.logallrefupdates true &&
1298+
1299+
# double push to test both with and without
1300+
# the actual pack transfer
1301+
git push dst.git master:one &&
1302+
echo "one@{0} push" >expect &&
1303+
git -C dst.git log -g --format="%gd %gs" one >actual &&
1304+
test_cmp expect actual &&
1305+
1306+
git push dst.git master:two &&
1307+
echo "two@{0} push" >expect &&
1308+
git -C dst.git log -g --format="%gd %gs" two >actual &&
1309+
test_cmp expect actual
1310+
'
1311+
1312+
test_expect_success 'fetch into bare respects core.logallrefupdates' '
1313+
rm -rf dst.git &&
1314+
git init --bare dst.git &&
1315+
(
1316+
cd dst.git &&
1317+
git config core.logallrefupdates true &&
1318+
1319+
# as above, we double-fetch to test both
1320+
# with and without pack transfer
1321+
git fetch .. master:one &&
1322+
echo "one@{0} fetch .. master:one: storing head" >expect &&
1323+
git log -g --format="%gd %gs" one >actual &&
1324+
test_cmp expect actual &&
1325+
1326+
git fetch .. master:two &&
1327+
echo "two@{0} fetch .. master:two: storing head" >expect &&
1328+
git log -g --format="%gd %gs" two >actual &&
1329+
test_cmp expect actual
1330+
)
1331+
'
1332+
12931333
test_done

0 commit comments

Comments
 (0)