git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] Shallow fetch can result in broken git repo

From
KKKacper 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~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
Next: Nguyễn Thái Ngọc Duy
Message 1 of 3 in “[BUG] Shallow fetch can result in broken git repo”
  1. Kacper KornetAug 26, 2013
  2. fetch-pack: do not remove .git/shallow file when --depth is not specifiedNguyễn Thái Ngọc Duy, Aug 26, 2013
  3. Junio C HamanoAug 26, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.