commit-graph.c: ensure graph layers respect core.sharedRepository
Non-layered commit-graphs use 'adjust_shared_perm' to make the commit-graph file readable (or not) to a combination of the user, group, and others. Call 'adjust_shared_perm' for split-graph layers to make sure that these also respect 'core.sharedRepository'. The 'commit-graph-chain' file already respects this configuration since it uses 'hold_lock_file_for_update' (which calls 'adjust_shared_perm' eventually in 'create_tempfile_mode'). Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Apr 29, 2020 at 11:36 UTC
f4d62847a431af965b8a6895b92f4372042457b0
2 files changed
+28
commit-graph.c
+6
@@ -1386,6 +1386,12 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1386
return -1;
1387
}
1388
1389
+ if (adjust_shared_perm(ctx->graph_name)) {
1390
+ error(_("unable to adjust shared permissions for '%s'"),
1391
+ ctx->graph_name);
1392
+ return -1;
1393
+ }
1394
+
1395
f = hashfd(fd, ctx->graph_name);
1396
} else {
1397
hold_lock_file_for_update_mode(&lk, ctx->graph_name,
t/t5324-split-commit-graph.sh
+22
@@ -36,6 +36,10 @@ graph_read_expect() {
36
test_cmp expect output
37
}
38
39
+test_expect_success POSIXPERM 'tweak umask for modebit tests' '
40
+ umask 022
41
+'
42
+
43
test_expect_success 'create commits and write commit-graph' '
44
for i in $(test_seq 3)
45
do
@@ -351,4 +355,22 @@ test_expect_success 'split across alternate where alternate is not split' '
355
test_cmp commit-graph .git/objects/info/commit-graph
356
'
357
358
+while read mode modebits
359
+do
360
+ test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" '
361
+ rm -rf $graphdir $infodir/commit-graph &&
362
+ git reset --hard commits/1 &&
363
+ test_config core.sharedrepository "$mode" &&
364
+ git commit-graph write --split --reachable &&
365
+ ls $graphdir/graph-*.graph >graph-files &&
366
+ test_line_count = 1 graph-files &&
367
+ echo "$modebits" >expect &&
368
+ test_modebits $graphdir/graph-*.graph >actual &&
369
+ test_cmp expect actual
370
+ '
371
+done <<\EOF
372
+0666 -r--r--r--
373
+0600 -r--------
374
+EOF
375
+
376
test_done