Browse code

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

Junio C Hamano authored on 06/11/2014 18:52:31
Showing 4 changed files
... ...
@@ -68,7 +68,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
68 68
 		fetch_prune_config = git_config_bool(k, v);
69 69
 		return 0;
70 70
 	}
71
-	return 0;
71
+	return git_default_config(k, v, cb);
72 72
 }
73 73
 
74 74
 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
... ...
@@ -2962,10 +2962,10 @@ int log_ref_setup(const char *refname, char *logfile, int bufsize)
2962 2962
 
2963 2963
 	logfd = open(logfile, oflags, 0666);
2964 2964
 	if (logfd < 0) {
2965
-		if (!(oflags & O_CREAT) && errno == ENOENT)
2965
+		if (!(oflags & O_CREAT) && (errno == ENOENT || errno == EISDIR))
2966 2966
 			return 0;
2967 2967
 
2968
-		if ((oflags & O_CREAT) && errno == EISDIR) {
2968
+		if (errno == EISDIR) {
2969 2969
 			if (remove_empty_directories(logfile)) {
2970 2970
 				int save_errno = errno;
2971 2971
 				error("There are still logs under '%s'",
... ...
@@ -253,4 +253,38 @@ test_expect_success 'checkout should not delete log for packed ref' '
253 253
 	test $(git reflog master | wc -l) = 4
254 254
 '
255 255
 
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
+
256 290
 test_done
... ...
@@ -11,6 +11,7 @@ This test checks the following functionality:
11 11
 * hooks
12 12
 * --porcelain output format
13 13
 * hiderefs
14
+* reflogs
14 15
 '
15 16
 
16 17
 . ./test-lib.sh
... ...
@@ -1290,4 +1291,43 @@ test_expect_success 'pushing a tag pushes the tagged object' '
1290 1290
 	test_cmp expect actual
1291 1291
 '
1292 1292
 
1293
+test_expect_success 'push into bare respects core.logallrefupdates' '
1294
+	rm -rf dst.git &&
1295
+	git init --bare dst.git &&
1296
+	git -C dst.git config core.logallrefupdates true &&
1297
+
1298
+	# double push to test both with and without
1299
+	# the actual pack transfer
1300
+	git push dst.git master:one &&
1301
+	echo "one@{0} push" >expect &&
1302
+	git -C dst.git log -g --format="%gd %gs" one >actual &&
1303
+	test_cmp expect actual &&
1304
+
1305
+	git push dst.git master:two &&
1306
+	echo "two@{0} push" >expect &&
1307
+	git -C dst.git log -g --format="%gd %gs" two >actual &&
1308
+	test_cmp expect actual
1309
+'
1310
+
1311
+test_expect_success 'fetch into bare respects core.logallrefupdates' '
1312
+	rm -rf dst.git &&
1313
+	git init --bare dst.git &&
1314
+	(
1315
+		cd dst.git &&
1316
+		git config core.logallrefupdates true &&
1317
+
1318
+		# as above, we double-fetch to test both
1319
+		# with and without pack transfer
1320
+		git fetch .. master:one &&
1321
+		echo "one@{0} fetch .. master:one: storing head" >expect &&
1322
+		git log -g --format="%gd %gs" one >actual &&
1323
+		test_cmp expect actual &&
1324
+
1325
+		git fetch .. master:two &&
1326
+		echo "two@{0} fetch .. master:two: storing head" >expect &&
1327
+		git log -g --format="%gd %gs" two >actual &&
1328
+		test_cmp expect actual
1329
+	)
1330
+'
1331
+
1293 1332
 test_done