fetch-pack: do not remove .git/shallow file when --depth is not specified
commit6da8bdcbbfd5ac9c4a92de79d7b4343d5d6bd4c5
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 26 Aug 2013 02:17:26 +0000 (26 09:17 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Aug 2013 05:56:03 +0000 (25 22:56 -0700)
tree5fba6f110fd63d02190cd5bcb4cb448791a99a3c
parenta3bc3d070cacf07dbe11b4bfec57554c8bbf1957
fetch-pack: do not remove .git/shallow file when --depth is not specified

fetch_pack() can remove .git/shallow file when a shallow repository
becomes a full one again. This behavior is triggered incorrectly when
tags are also fetched because fetch_pack() will be called twice. At
the first fetch_pack() call:

 - shallow_lock is set up
 - alternate_shallow_file points to shallow_lock.filename, which is
   "shallow.lock"
 - commit_lock_file is called, which sets shallow_lock.filename to "".
   alternate_shallow_file also becomes "" because it points to the
   same memory.

At the second call, setup_alternate_shallow() is not called and
alternate_shallow_file remains "". It's mistaken as unshallow case and
.git/shallow is removed. The end result is a broken repository.

Fix this by always initializing alternate_shallow_file when
fetch_pack() is called. As an extra measure, check if args->depth > 0
before commit/rollback shallow file.

Reported-by: Kacper Kornet <kornet@camk.edu.pl>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fetch-pack.c
t/t5500-fetch-pack.sh