Skip to content

Commit 65381e4

Browse files
committed
Merge branch 'as/show-index-uninitialized-hash' into jch
Regression fix for 'show-index' when run outside of a repository. Comments? * as/show-index-uninitialized-hash: t5300: add test for 'show-index --object-format' show-index: fix uninitialized hash function
2 parents a59d166 + 34d3f2a commit 65381e4

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
@@ -38,6 +38,15 @@ int cmd_show_index(int argc,
3838
repo_set_hash_algo(the_repository, hash_algo);
3939
}
4040

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

4352
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
@@ -528,6 +528,24 @@ test_expect_success 'index-pack --strict <pack> works in non-repo' '
528528
test_path_is_file foo.idx
529529
'
530530

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

0 commit comments

Comments
 (0)