Skip to content

Commit 49d45de

Browse files
committed
Merge branch 'jk/index-pack-wo-repo-from-stdin'
"git index-pack --stdin" needs an access to an existing repository, but "git index-pack file.pack" to generate an .idx file that corresponds to a packfile does not. * jk/index-pack-wo-repo-from-stdin: index-pack: skip collision check when not in repository t: use nongit() function where applicable index-pack: complain when --stdin is used outside of a repo t5000: extract nongit function to test-lib-functions.sh
2 parents 47021ef + 29401e1 commit 49d45de

File tree

7 files changed

+42
-47
lines changed

7 files changed

+42
-47
lines changed

builtin/index-pack.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,15 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
787787
const unsigned char *sha1)
788788
{
789789
void *new_data = NULL;
790-
int collision_test_needed;
790+
int collision_test_needed = 0;
791791

792792
assert(data || obj_entry);
793793

794-
read_lock();
795-
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
796-
read_unlock();
794+
if (startup_info->have_repository) {
795+
read_lock();
796+
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
797+
read_unlock();
798+
}
797799

798800
if (collision_test_needed && !data) {
799801
read_lock();
@@ -1730,6 +1732,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17301732
usage(index_pack_usage);
17311733
if (fix_thin_pack && !from_stdin)
17321734
die(_("--fix-thin cannot be used without --stdin"));
1735+
if (from_stdin && !startup_info->have_repository)
1736+
die(_("--stdin requires a git repository"));
17331737
if (!index_name && pack_name)
17341738
index_name = derive_filename(pack_name, ".idx", &index_name_buf);
17351739
if (keep_msg && !keep_name && pack_name)

t/t1308-config-set.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,8 @@ test_expect_success 'check line errors for malformed values' '
219219
'
220220

221221
test_expect_success 'error on modifying repo config without repo' '
222-
mkdir no-repo &&
223-
(
224-
GIT_CEILING_DIRECTORIES=$(pwd) &&
225-
export GIT_CEILING_DIRECTORIES &&
226-
cd no-repo &&
227-
test_must_fail git config a.b c 2>err &&
228-
grep "not in a git directory" err
229-
)
222+
nongit test_must_fail git config a.b c 2>err &&
223+
grep "not in a git directory" err
230224
'
231225

232226
cmdline_config="'foo.bar=from-cmdline'"

t/t5000-tar-tree.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,6 @@ check_tar() {
9494
'
9595
}
9696

97-
# run "$@" inside a non-git directory
98-
nongit () {
99-
test -d non-repo ||
100-
mkdir non-repo ||
101-
return 1
102-
103-
(
104-
GIT_CEILING_DIRECTORIES=$(pwd) &&
105-
export GIT_CEILING_DIRECTORIES &&
106-
cd non-repo &&
107-
"$@"
108-
)
109-
}
110-
11197
test_expect_success \
11298
'populate workdir' \
11399
'mkdir a &&

t/t5300-pack-object.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,21 @@ test_expect_success 'verify resulting packs' '
406406
git verify-pack test-11-*.pack
407407
'
408408

409+
test_expect_success 'set up pack for non-repo tests' '
410+
# make sure we have a pack with no matching index file
411+
cp test-1-*.pack foo.pack
412+
'
413+
414+
test_expect_success 'index-pack --stdin complains of non-repo' '
415+
nongit test_must_fail git index-pack --stdin <foo.pack &&
416+
test_path_is_missing non-repo/.git
417+
'
418+
419+
test_expect_success 'index-pack <pack> works in non-repo' '
420+
nongit git index-pack ../foo.pack &&
421+
test_path_is_file foo.idx
422+
'
423+
409424
#
410425
# WARNING!
411426
#

t/t9100-git-svn-basic.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,12 @@ case "$GIT_SVN_LC_ALL" in
1717
;;
1818
esac
1919

20-
deepdir=nothing-above
21-
ceiling=$PWD
22-
2320
test_expect_success 'git svn --version works anywhere' '
24-
mkdir -p "$deepdir" && (
25-
GIT_CEILING_DIRECTORIES="$ceiling" &&
26-
export GIT_CEILING_DIRECTORIES &&
27-
cd "$deepdir" &&
28-
git svn --version
29-
)
21+
nongit git svn --version
3022
'
3123

3224
test_expect_success 'git svn help works anywhere' '
33-
mkdir -p "$deepdir" && (
34-
GIT_CEILING_DIRECTORIES="$ceiling" &&
35-
export GIT_CEILING_DIRECTORIES &&
36-
cd "$deepdir" &&
37-
git svn help
38-
)
25+
nongit git svn help
3926
'
4027

4128
test_expect_success \

t/t9902-completion.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,7 @@ test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
257257
'
258258

259259
test_expect_success '__gitdir - not a git repository' '
260-
(
261-
cd subdir/subsubdir &&
262-
GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY" &&
263-
export GIT_CEILING_DIRECTORIES &&
264-
test_must_fail __gitdir
265-
)
260+
nongit test_must_fail __gitdir
266261
'
267262

268263
test_expect_success '__gitcomp - trailing space - options' '

t/test-lib-functions.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,3 +994,17 @@ test_copy_bytes () {
994994
}
995995
' - "$1"
996996
}
997+
998+
# run "$@" inside a non-git directory
999+
nongit () {
1000+
test -d non-repo ||
1001+
mkdir non-repo ||
1002+
return 1
1003+
1004+
(
1005+
GIT_CEILING_DIRECTORIES=$(pwd) &&
1006+
export GIT_CEILING_DIRECTORIES &&
1007+
cd non-repo &&
1008+
"$@"
1009+
)
1010+
}

0 commit comments

Comments
 (0)