Skip to content

Commit 2ea3df6

Browse files
committed
Merge branch 'nd/fetch-pack-shallow-fix' into maint
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
2 parents bda7904 + 6da8bdc commit 2ea3df6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

fetch-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
897897
packet_flush(fd[1]);
898898
if (args->depth > 0)
899899
setup_alternate_shallow();
900+
else
901+
alternate_shallow_file = NULL;
900902
if (get_pack(args, fd, pack_lockfile))
901903
die("git fetch-pack: fetch failed.");
902904

@@ -987,7 +989,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
987989
}
988990
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
989991

990-
if (alternate_shallow_file) {
992+
if (args->depth > 0 && alternate_shallow_file) {
991993
if (*alternate_shallow_file == '\0') { /* --unshallow */
992994
unlink_or_warn(git_path("shallow"));
993995
rollback_lock_file(&shallow_lock);

t/t5500-fetch-pack.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,20 @@ test_expect_success 'test --all, --depth, and explicit tag' '
505505
) >out-adt 2>error-adt
506506
'
507507

508+
test_expect_success 'shallow fetch with tags does not break the repository' '
509+
mkdir repo1 &&
510+
(
511+
cd repo1 &&
512+
git init &&
513+
test_commit 1 &&
514+
test_commit 2 &&
515+
test_commit 3 &&
516+
mkdir repo2 &&
517+
cd repo2 &&
518+
git init &&
519+
git fetch --depth=2 ../.git master:branch &&
520+
git fsck
521+
)
522+
'
523+
508524
test_done

0 commit comments

Comments
 (0)