Fourth batch
[gitweb.git] / t / t5318-commit-graph.sh
index 0d012f55e559e83823ff27235f60a83b1ba4c5fd..ab3eccf0fafa3f8e9158b6347a544a8b4202b7ce 100755 (executable)
@@ -20,7 +20,14 @@ test_expect_success 'verify graph with no graph file' '
 test_expect_success 'write graph with no packs' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write --object-dir . &&
-       test_path_is_file info/commit-graph
+       test_path_is_missing info/commit-graph
+'
+
+test_expect_success 'exit with correct error on bad input to --stdin-packs' '
+       cd "$TRASH_DIRECTORY/full" &&
+       echo doesnotexist >in &&
+       test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
+       test_i18ngrep "error adding pack" stderr
 '
 
 test_expect_success 'create commits and repack' '
@@ -33,6 +40,15 @@ test_expect_success 'create commits and repack' '
        git repack
 '
 
+test_expect_success 'exit with correct error on bad input to --stdin-commits' '
+       cd "$TRASH_DIRECTORY/full" &&
+       echo HEAD | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr &&
+       test_i18ngrep "invalid commit object id" stderr &&
+       # valid tree OID, but not a commit OID
+       git rev-parse HEAD^{tree} | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr &&
+       test_i18ngrep "invalid commit object id" stderr
+'
+
 graph_git_two_modes() {
        git -c core.commitGraph=true $1 >output
        git -c core.commitGraph=false $1 >expect
@@ -75,7 +91,7 @@ graph_read_expect() {
 
 test_expect_success 'write graph' '
        cd "$TRASH_DIRECTORY/full" &&
-       graph1=$(git commit-graph write) &&
+       git commit-graph write &&
        test_path_is_file $objdir/info/commit-graph &&
        graph_read_expect "3"
 '
@@ -377,7 +393,13 @@ corrupt_graph_verify() {
        test_must_fail git commit-graph verify 2>test_err &&
        grep -v "^+" test_err >err &&
        test_i18ngrep "$grepstr" err &&
-       git status --short
+       if test "$2" != "no-copy"
+       then
+               cp $objdir/info/commit-graph commit-graph-pre-write-test
+       fi &&
+       git status --short &&
+       GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
+       git commit-graph verify
 }
 
 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
@@ -394,12 +416,18 @@ corrupt_graph_and_verify() {
        orig_size=$(wc -c < $objdir/info/commit-graph) &&
        zero_pos=${4:-${orig_size}} &&
        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" &&
        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 &&
@@ -516,6 +544,7 @@ test_expect_success 'git fsck (checks commit-graph)' '
        git fsck &&
        corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
                "incorrect checksum" &&
+       cp commit-graph-pre-write-test $objdir/info/commit-graph &&
        test_must_fail git fsck
 '