Merge branch 'ab/commit-graph-fixes'
authorJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2019 07:41:15 +0000 (16:41 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2019 07:41:15 +0000 (16:41 +0900)
Code cleanup with more careful error checking before using data
read from the commit-graph file.

* ab/commit-graph-fixes:
commit-graph: improve & i18n error messages
commit-graph write: don't die if the existing graph is corrupt
commit-graph verify: detect inability to read the graph
commit-graph: don't pass filename to load_commit_graph_one_fd_st()
commit-graph: don't early exit(1) on e.g. "git status"
commit-graph: fix segfault on e.g. "git status"
commit-graph tests: test a graph that's too small
commit-graph tests: split up corrupt_graph_and_verify()

1  2 
t/t5318-commit-graph.sh
index 069e4e28e42d69e7b892112f3ba3743e4e13edac,e80c1cac02b26239c510765cdd8fb28dc9bafba1..840ad4d8accbfef59e2c9ade82105cc717f6866c
@@@ -376,19 -396,28 +396,28 @@@ corrupt_graph_and_verify() 
        pos=$1
        data="${2:-\0}"
        grepstr=$3
-       cd "$TRASH_DIRECTORY/full" &&
+       corrupt_graph_setup &&
        orig_size=$(wc -c < $objdir/info/commit-graph) &&
        zero_pos=${4:-${orig_size}} &&
-       test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
-       cp $objdir/info/commit-graph commit-graph-backup &&
        printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
 -      dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=0 &&
 +      dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
        generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
-       test_must_fail git commit-graph verify 2>test_err &&
-       grep -v "^+" test_err >err &&
-       test_i18ngrep "$grepstr" err
+       corrupt_graph_verify "$grepstr"
  }
  
+ test_expect_success POSIXPERM,SANITY 'detect permission problem' '
+       corrupt_graph_setup &&
+       chmod 000 $objdir/info/commit-graph &&
+       corrupt_graph_verify "Could not open" "no-copy"
+ '
+ test_expect_success 'detect too small' '
+       corrupt_graph_setup &&
+       echo "a small graph" >$objdir/info/commit-graph &&
+       corrupt_graph_verify "too small"
+ '
  test_expect_success 'detect bad signature' '
        corrupt_graph_and_verify 0 "\0" \
                "graph signature"