Skip to content

Commit 002a8a9

Browse files
committed
Merge branch 'as/show-index-uninitialized-hash'
Regression fix for 'show-index' when run outside of a repository. * as/show-index-uninitialized-hash: t5300: add test for 'show-index --object-format' show-index: fix uninitialized hash function
2 parents 4156b6a + 34d3f2a commit 002a8a9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

builtin/show-index.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ int cmd_show_index(int argc,
4040
repo_set_hash_algo(the_repository, hash_algo);
4141
}
4242

43+
/*
44+
* Fallback to SHA1 if we are running outside of a repository.
45+
*
46+
* TODO: Figure out and implement a way to detect the hash algorithm in use by the
47+
* the index file passed in and use that instead.
48+
*/
49+
if (!the_hash_algo)
50+
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
51+
4352
hashsz = the_hash_algo->rawsz;
4453

4554
if (fread(top_index, 2 * 4, 1, stdin) != 1)

t/t5300-pack-object.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,24 @@ test_expect_success 'index-pack --strict <pack> works in non-repo' '
525525
test_path_is_file foo.idx
526526
'
527527

528+
test_expect_success SHA1 'show-index works OK outside a repository' '
529+
nongit git show-index <foo.idx
530+
'
531+
532+
for hash in sha1 sha256
533+
do
534+
test_expect_success 'show-index works OK outside a repository with hash algo passed in via --object-format' '
535+
test_when_finished "rm -rf explicit-hash-$hash" &&
536+
git init --object-format=$hash explicit-hash-$hash &&
537+
test_commit -C explicit-hash-$hash one &&
538+
git -C explicit-hash-$hash rev-parse one >in &&
539+
git -C explicit-hash-$hash pack-objects explicit-hash-$hash <in &&
540+
idx=$(echo explicit-hash-$hash/explicit-hash-$hash*.idx) &&
541+
nongit git show-index --object-format=$hash <"$idx" >actual &&
542+
test_line_count = 1 actual
543+
'
544+
done
545+
528546
test_expect_success !PTHREADS,!FAIL_PREREQS \
529547
'index-pack --threads=N or pack.threads=N warns when no pthreads' '
530548
test_must_fail git index-pack --threads=2 2>err &&

0 commit comments

Comments
 (0)