git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] Shallow fetch can result in broken git repo
@ 2013-08-26  0:22 Kacper Kornet
  2013-08-26  2:17 ` [PATCH] fetch-pack: do not remove .git/shallow file when --depth is not specified Nguyễn Thái Ngọc Duy
  0 siblings, 1 reply; 3+ messages in thread
From: Kacper Kornet @ 2013-08-26  0:22 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Starting from "6035d6a fetch-pack: prepare updated shallow file before
fetching the pack" the shallow fetches of commits with tags can result
in broken git repo.  The following script illustrates the problem:

#!/bin/sh

mkdir repo1 repo2
cd repo1
git init
for i in `seq 1 3`; do
        echo $i > foo
        git add foo
        git commit -m "Commit $i"
done
git tag tag HEAD~1

cd ../repo2
git init
git fetch --depth=2 ../repo1 master:branch
git fsck

The function fetch_pack in this case is called twice. During the
second called alternate_shallow_file contains "\0" (it is set to this
value by commit_lock_file(&shallow_lock) during first call of
fetch_pack). In the result the file .git/shallow, created during first
call to fetch_pack, is removed and the git repo ends with broken link.

The two possible fixes which I see are:

1) Replace back if (alternate_shallow_file) condition in fetch pack with 
   if (args->depth > 0) 

2) alternate_shallow_file should be copy of shallow_lock.filename not a
   reference to it

But I'm not able to determine by myself which one (if any) is a correct fix
to the problem.

-- 
  Kacper

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-26  6:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-26  0:22 [BUG] Shallow fetch can result in broken git repo Kacper Kornet
2013-08-26  2:17 ` [PATCH] fetch-pack: do not remove .git/shallow file when --depth is not specified Nguyễn Thái Ngọc Duy
2013-08-26  6:09   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).