[BUG] Shallow fetch can result in broken git repo
- From
- Kacper Kornet <kornet@camk.edu.pl>
- Date
- Aug 26, 2013, 00:22 UTC
- Message-ID
- <20130826002202.GA26940@camk.edu.pl>
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~1cd ../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