Merge branch 'jk/index-pack-wo-repo-from-stdin'
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Dec 2016 22:55:03 +0000 (14:55 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Dec 2016 22:55:03 +0000 (14:55 -0800)
"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

builtin/index-pack.c
t/t1308-config-set.sh
t/t5000-tar-tree.sh
t/t5300-pack-object.sh
t/t9100-git-svn-basic.sh
t/t9902-completion.sh
t/test-lib-functions.sh
index 0a27bab11b6b5a1b162c4dfef34c645c7d5f14ad..f4b87c6c9f901e5834ce9e50db089fb487c6eafc 100644 (file)
@@ -787,13 +787,15 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
                        const unsigned char *sha1)
 {
        void *new_data = NULL;
-       int collision_test_needed;
+       int collision_test_needed = 0;
 
        assert(data || obj_entry);
 
-       read_lock();
-       collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
-       read_unlock();
+       if (startup_info->have_repository) {
+               read_lock();
+               collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
+               read_unlock();
+       }
 
        if (collision_test_needed && !data) {
                read_lock();
@@ -1730,6 +1732,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                usage(index_pack_usage);
        if (fix_thin_pack && !from_stdin)
                die(_("--fix-thin cannot be used without --stdin"));
+       if (from_stdin && !startup_info->have_repository)
+               die(_("--stdin requires a git repository"));
        if (!index_name && pack_name)
                index_name = derive_filename(pack_name, ".idx", &index_name_buf);
        if (keep_msg && !keep_name && pack_name)
index 7655c94c2801f0070a7b60ea17f30414b16c8d12..ff50960ccaed9953c5738c9bbf602bf0d326e15a 100755 (executable)
@@ -219,14 +219,8 @@ test_expect_success 'check line errors for malformed values' '
 '
 
 test_expect_success 'error on modifying repo config without repo' '
-       mkdir no-repo &&
-       (
-               GIT_CEILING_DIRECTORIES=$(pwd) &&
-               export GIT_CEILING_DIRECTORIES &&
-               cd no-repo &&
-               test_must_fail git config a.b c 2>err &&
-               grep "not in a git directory" err
-       )
+       nongit test_must_fail git config a.b c 2>err &&
+       grep "not in a git directory" err
 '
 
 cmdline_config="'foo.bar=from-cmdline'"
index 830bf2a2f6d4d85358a54f58f74b4ed9fdc954d5..886b6953e40f9fceae18642ebec031e0bdf511e3 100755 (executable)
@@ -94,20 +94,6 @@ check_tar() {
        '
 }
 
-# run "$@" inside a non-git directory
-nongit () {
-       test -d non-repo ||
-       mkdir non-repo ||
-       return 1
-
-       (
-               GIT_CEILING_DIRECTORIES=$(pwd) &&
-               export GIT_CEILING_DIRECTORIES &&
-               cd non-repo &&
-               "$@"
-       )
-}
-
 test_expect_success \
     'populate workdir' \
     'mkdir a &&
index 899e52d50f0d73e4a755c4f7991364f34912b336..43a672c3451146f800852a6d8688c10e497b47cf 100755 (executable)
@@ -406,6 +406,21 @@ test_expect_success 'verify resulting packs' '
        git verify-pack test-11-*.pack
 '
 
+test_expect_success 'set up pack for non-repo tests' '
+       # make sure we have a pack with no matching index file
+       cp test-1-*.pack foo.pack
+'
+
+test_expect_success 'index-pack --stdin complains of non-repo' '
+       nongit test_must_fail git index-pack --stdin <foo.pack &&
+       test_path_is_missing non-repo/.git
+'
+
+test_expect_success 'index-pack <pack> works in non-repo' '
+       nongit git index-pack ../foo.pack &&
+       test_path_is_file foo.idx
+'
+
 #
 # WARNING!
 #
index 92a3aa8063f810bd2b8df68f3f0f30c2faf3bdc6..8a8ba65a2ae583aa5d0b0526e604a8f9613b5a5e 100755 (executable)
@@ -17,25 +17,12 @@ case "$GIT_SVN_LC_ALL" in
        ;;
 esac
 
-deepdir=nothing-above
-ceiling=$PWD
-
 test_expect_success 'git svn --version works anywhere' '
-       mkdir -p "$deepdir" && (
-               GIT_CEILING_DIRECTORIES="$ceiling" &&
-               export GIT_CEILING_DIRECTORIES &&
-               cd "$deepdir" &&
-               git svn --version
-       )
+       nongit git svn --version
 '
 
 test_expect_success 'git svn help works anywhere' '
-       mkdir -p "$deepdir" && (
-               GIT_CEILING_DIRECTORIES="$ceiling" &&
-               export GIT_CEILING_DIRECTORIES &&
-               cd "$deepdir" &&
-               git svn help
-       )
+       nongit git svn help
 '
 
 test_expect_success \
index 2ba62fbc178e1c92dff493beebdc9683b36efd2a..a34e55f874ca06da4cae6ab5d46bc3263c58d521 100755 (executable)
@@ -257,12 +257,7 @@ test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
 '
 
 test_expect_success '__gitdir - not a git repository' '
-       (
-               cd subdir/subsubdir &&
-               GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY" &&
-               export GIT_CEILING_DIRECTORIES &&
-               test_must_fail __gitdir
-       )
+       nongit test_must_fail __gitdir
 '
 
 test_expect_success '__gitcomp - trailing space - options' '
index fdaeb3a96bed361f53030cb6ea5c6bdde445163f..adab7f51f4c962967c90e3184853377feece2b1e 100644 (file)
@@ -994,3 +994,17 @@ test_copy_bytes () {
                }
        ' - "$1"
 }
+
+# run "$@" inside a non-git directory
+nongit () {
+       test -d non-repo ||
+       mkdir non-repo ||
+       return 1
+
+       (
+               GIT_CEILING_DIRECTORIES=$(pwd) &&
+               export GIT_CEILING_DIRECTORIES &&
+               cd non-repo &&
+               "$@"
+       )
+}