Skip to content

Commit da9acde

Browse files
derrickstoleegitster
authored andcommitted
test-lib-functions: add helper for trailing hash
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. This confirms that when the config is disabled explicitly in a super project but enabled in a submodule, then the use of repo_config_get_bool() loads config from the correct repository in the case of 'git add'. There are other cases where istate->repo is NULL and thus this config is loaded instead from the_repository, but that's due to many different code paths initializing index_state structs in their own way. 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee1f0c2 commit da9acde

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

t/t1600-index.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ test_expect_success 'out of bounds index.version issues warning' '
6868
test_expect_success 'index.skipHash config option' '
6969
rm -f .git/index &&
7070
git -c index.skipHash=true add a &&
71+
test_trailing_hash .git/index >hash &&
72+
echo $(test_oid zero) >expect &&
73+
test_cmp expect hash &&
7174
git fsck &&
7275
7376
test_commit start &&
@@ -76,6 +79,8 @@ test_expect_success 'index.skipHash config option' '
7679
git -C sub config index.skipHash true &&
7780
>sub/file &&
7881
git -C sub add a &&
82+
test_trailing_hash .git/modules/sub/index >hash &&
83+
test_cmp expect hash &&
7984
git -C sub fsck
8085
'
8186

t/test-lib-functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,3 +1875,11 @@ test_cmp_config_output () {
18751875
sort config-actual >sorted-actual &&
18761876
test_cmp sorted-expect sorted-actual
18771877
}
1878+
1879+
# Given a filename, extract its trailing hash as a hex string
1880+
test_trailing_hash () {
1881+
local file="$1" &&
1882+
tail -c $(test_oid rawsz) "$file" |
1883+
test-tool hexdump |
1884+
sed "s/ //g"
1885+
}

0 commit comments

Comments
 (0)