Skip to content

Commit f6761fa

Browse files
avargitster
authored andcommitted
commit-graph tests: split up corrupt_graph_and_verify()
Split up the corrupt_graph_and_verify() function added in d9b9f8a ("commit-graph: verify catches corrupt signature", 2018-06-27) into its logical components of setting up the test itself, doing the corruption in a particular way with "dd", and then finally testing that stderr is what we expect. This allows for re-using everything except the now slimmer corrupt_graph_and_verify() to corrupt the graph in a way that doesn't involve inserting a given byte sequence at a given position, e.g. truncating it entirely to a custom value. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35ee755 commit f6761fa

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

t/t5318-commit-graph.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,19 @@ GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
366366
GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
367367
GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
368368

369+
corrupt_graph_setup() {
370+
cd "$TRASH_DIRECTORY/full" &&
371+
test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
372+
cp $objdir/info/commit-graph commit-graph-backup
373+
}
374+
375+
corrupt_graph_verify() {
376+
grepstr=$1
377+
test_must_fail git commit-graph verify 2>test_err &&
378+
grep -v "^+" test_err >err &&
379+
test_i18ngrep "$grepstr" err
380+
}
381+
369382
# usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
370383
# Manipulates the commit-graph file at the position
371384
# by inserting the data, optionally zeroing the file
@@ -376,17 +389,14 @@ corrupt_graph_and_verify() {
376389
pos=$1
377390
data="${2:-\0}"
378391
grepstr=$3
379-
cd "$TRASH_DIRECTORY/full" &&
392+
corrupt_graph_setup &&
380393
orig_size=$(wc -c < $objdir/info/commit-graph) &&
381394
zero_pos=${4:-${orig_size}} &&
382-
test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
383-
cp $objdir/info/commit-graph commit-graph-backup &&
384395
printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
385396
dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=0 &&
386397
generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
387-
test_must_fail git commit-graph verify 2>test_err &&
388-
grep -v "^+" test_err >err &&
389-
test_i18ngrep "$grepstr" err
398+
corrupt_graph_verify "$grepstr"
399+
390400
}
391401

392402
test_expect_success 'detect bad signature' '

0 commit comments

Comments
 (0)