Merge branch 'nd/fetch-pack-shallow-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2013 21:40:58 +0000 (14:40 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2013 21:40:58 +0000 (14:40 -0700)
The recent "short-cut clone connectivity check" topic broke a shallow
repository when a fetch operation tries to auto-follow tags.

* nd/fetch-pack-shallow-fix:
fetch-pack: do not remove .git/shallow file when --depth is not specified

fetch-pack.c
t/t5500-fetch-pack.sh
index 6684348c0ec9ea742eb98666b56a0bfcef316560..f5d99c11813b1ae2eee0bb7dfd94eab60c721b64 100644 (file)
@@ -897,6 +897,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
                packet_flush(fd[1]);
        if (args->depth > 0)
                setup_alternate_shallow();
+       else
+               alternate_shallow_file = NULL;
        if (get_pack(args, fd, pack_lockfile))
                die("git fetch-pack: fetch failed.");
 
@@ -987,7 +989,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
        }
        ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
 
-       if (alternate_shallow_file) {
+       if (args->depth > 0 && alternate_shallow_file) {
                if (*alternate_shallow_file == '\0') { /* --unshallow */
                        unlink_or_warn(git_path("shallow"));
                        rollback_lock_file(&shallow_lock);
index fd2598e60190fe04381652c7dfe997e01b4ea0c5..a80584ea0eaba854ff21318e3c9646f72325bee7 100755 (executable)
@@ -505,4 +505,20 @@ test_expect_success 'test --all, --depth, and explicit tag' '
        ) >out-adt 2>error-adt
 '
 
+test_expect_success 'shallow fetch with tags does not break the repository' '
+       mkdir repo1 &&
+       (
+               cd repo1 &&
+               git init &&
+               test_commit 1 &&
+               test_commit 2 &&
+               test_commit 3 &&
+               mkdir repo2 &&
+               cd repo2 &&
+               git init &&
+               git fetch --depth=2 ../.git master:branch &&
+               git fsck
+       )
+'
+
 test_done