summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fetch-pack.c4
-rwxr-xr-xt/t5500-fetch-pack.sh16
2 files changed, 19 insertions, 1 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index 6b5467c6de..76190a8fbd 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -888,6 +888,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.");
@@ -978,7 +980,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);
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index fd2598e601..a80584ea0e 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -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