Skip to content

Commit

Permalink
test-lib-functions: add helper for trailing hash
Browse files Browse the repository at this point in the history
It can be helpful to check that a file format with a trailing hash has a
specific hash in the final bytes of a written file. This is made more
apparent by recent changes that allow skipping the hash algorithm and
writing a null hash at the end of the file instead.

Add a new test_trailing_hash helper and use it in t1600 to verify that
index.skipHash=true really does skip the hash computation, since
'git fsck' does not actually verify the hash.

Keep the 'git fsck' call to ensure that any potential future change to
check the index hash does not cause an error in this case.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
  • Loading branch information
derrickstolee committed Dec 7, 2022
1 parent 5fb4b5a commit a20bf8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions t/t1600-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ test_expect_success 'index.skipHash config option' '
(
rm -f .git/index &&
git -c index.skipHash=true add a &&
test_trailing_hash .git/index >hash &&
echo $(test_oid zero) >expect &&
test_cmp expect hash &&
git fsck
)
'
Expand Down
8 changes: 8 additions & 0 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1875,3 +1875,11 @@ test_cmp_config_output () {
sort config-actual >sorted-actual &&
test_cmp sorted-expect sorted-actual
}

# Given a filename, extract its trailing hash as a hex string
test_trailing_hash () {
local file="$1" &&
tail -c $(test_oid rawsz) "$file" | \
test-tool hexdump | \
sed "s/ //g"
}

0 comments on commit a20bf8d

Please sign in to comment.