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

Repository data loss in fast-export with a merge of a deleted submodule

From
Joshua Jensen <jjensen@workspacewhiz.com>
Date
Oct 27, 2011, 19:27 UTC
Message-ID
<4EA9B0B5.6060005@workspacewhiz.com>
Hello.

We had a submodule that we deleted and then added back into the repository at the same location as the former submodule. When running fast-export, the newly 'added' files for the merge commit are listed and then are followed with a:

M ... path/to/submodule/file D path/to/submodule

On fast-import, the resultant repository becomes corrupt due to the Delete instruction above occurring AFTER the file adds/modifications. The new repository does not match the old repository where the fast-export was performed.

I have included a repro script below. I have not been able to test this on Git 1.7.7.1, but I have tested on Git 1.7.7 (msysGit version).

Please compare the differences between the generated main.fe and newmain.fe files. newmain.fe has data loss.

I am not familiar with the fast-export code.  Can anyone help out?
Thanks.
Josh
---------
rm -rf main brokenmain sub main.fenewmain.fe

# Create the submodule. mkdir sub cd sub git init echo file > file git add file git commit -m file cd ..

# Create the main repository. mkdir main cd main git init

# Add the submodule. git submodule add ../sub sub git commit -m "Add submodule"

# Remove the submodule. rm -rf sub git rm sub .gitmodules git commit -m "Remove submodule"

# Add sub/file to the master branch.
mkdir sub
echo file > sub/file
git add sub/file
git commit -m "Add sub/file"
if [ -f sub/file ]; then
     echo "main: master branch: sub/file exists."
fi

# Delete the submodule directory manually, because we know that the incoming merge will need it gone. git checkout -B will-be-broken HEAD^^ rm -rf sub git merge --no-ff master

# sub/file exists within the 'will-be-broken' branch.
if [ -f sub/file ]; then
     echo "main: will-be-broken branch: sub/file exists."
fi

# Export out the main repository. git fast-export --all > ../main.fe

# Create the brokenmain repository. cd .. mkdir brokenmain cd brokenmain git init

# Import in everything from the main repository. git fast-import < ../main.fe

# sub/file exists within the master branch.
git checkout master
if [ -f sub/file ]; then
     echo "brokenmain: master branch: sub/file exists."
fi
# sub/file SHOULD exist within the 'will-be-broken' branch but doesn't.
git checkout will-be-broken
if [ ! -f sub/file ]; then
     echo "brokenmain: will-be-broken branch: sub/file SHOULD exist but 
doesn't."
fi

# Export out the brokenmain repository. git fast-export --all > ../brokenmain.fe

Next: Joshua Jensen
Message 1 of 5 in “Repository data loss in fast-export with a merge of a deleted submodule”
  1. Joshua JensenOct 27, 2011
  2. Joshua JensenNov 3, 2011
  3. Joshua JensenNov 14, 2011
  4. Jens LehmannNov 14, 2011
  5. Jeff KingNov 30, 2011

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.