Skip to content

Commit 7b8ce9c

Browse files
avargitster
authored andcommitted
commit-graph verify: detect inability to read the graph
Change "commit-graph verify" to error on open() failures other than ENOENT. As noted in the third paragraph of 283e68c ("commit-graph: add 'verify' subcommand", 2018-06-27) and the test it added it's intentional that "commit-graph verify" doesn't error out when the file doesn't exist. But let's not be overly promiscuous in what we accept. If we can't read the file for other reasons, e.g. permission errors, bad file descriptor etc. we'd like to report an error to the user. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 67a530f commit 7b8ce9c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

builtin/commit-graph.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ static int graph_verify(int argc, const char **argv)
6262

6363
graph_name = get_commit_graph_filename(opts.obj_dir);
6464
open_ok = open_commit_graph(graph_name, &fd, &st);
65-
if (!open_ok)
65+
if (!open_ok && errno == ENOENT)
6666
return 0;
67+
if (!open_ok)
68+
die_errno(_("Could not open commit-graph '%s'"), graph_name);
6769
graph = load_commit_graph_one_fd_st(fd, &st);
6870
FREE_AND_NULL(graph_name);
6971

t/t5318-commit-graph.sh

+6
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ corrupt_graph_and_verify() {
400400

401401
}
402402

403+
test_expect_success POSIXPERM,SANITY 'detect permission problem' '
404+
corrupt_graph_setup &&
405+
chmod 000 $objdir/info/commit-graph &&
406+
corrupt_graph_verify "Could not open"
407+
'
408+
403409
test_expect_success 'detect too small' '
404410
corrupt_graph_setup &&
405411
echo "a small graph" >$objdir/info/commit-graph &&

0 commit comments

Comments
 (0)