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

bug? round-trip through fast-import/fast-export loses files

From
PRPriedhorsky, Reid <reidpr@lanl.gov>
Date
Mar 20, 2023, 17:10 UTC
Message-ID
<BBB169A5-0665-47C9-819B-6409A22AB699@lanl.gov>
  Hello,
  I believe I’ve found a bug in Git. It seems that (1) round-tripping through
  fast-export/fast-import a repository (2) that contains a commit that changes
  a file to a directory (3) deletes the contents of that directory from the
  repository.

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
  Run this shell script:
  ~~~~
  #!/bin/bash
  set -ex
  mkdir -p /tmp/weirdal
  cd /tmp/weirdal
  git --version
  # init repo
  rm -Rf wd
  mkdir wd
  cd wd
  git init -b main
  # first commit - foo is a file
  touch foo
  git add -A
  git commit -m 'file'
  # second commit - foo is a directory
  rm foo
  mkdir foo
  touch foo/bar
  git add -A
  git commit -m 'directory'
  # the contents of foo are in the working dir and the repo
  git status
  ls -lR
  git ls-tree --name-only -r HEAD
  # import/export repository (add --full-tree to work around bug)
  git fast-export --no-data -- --all > ../export
  cat ../export
  git fast-import --force --quiet < ../export
  # bug: foo is still in the WD but not the repo; should still be both
  git status
  ls -lR
  git ls-tree --name-only -r HEAD
  #git fast-export --no-data -- --all | diff -u --text ../export - || true
  ~~~~
What did you expect to happen? (Expected behavior)
  Repo should be unchanged, i.e.:
  + git status
  On branch main
  nothing to commit, working tree clean
What happened instead? (Actual behavior)
  Git thinks foo/bar has been staged:
  + git status
  On branch main
  Changes to be committed:
    (use "git restore --staged <file>..." to unstage)
          new file:   foo/bar
What's different between what you expected and what actually happened?
  File foo/bar is staged when it should be unchanged.
Anything else you want to add:
  This also happens in 2.38.1 built from source.
  The bad behavior can be worked around with “--full-tree” on fast-export, but
  the real repo where I want to do this is pretty large, so I’d prefer not to.
  Note the “git fast-export” output:
    commit refs/heads/main
    mark :2
    author Reid Priedhorsky <reidpr@lanl.gov> 1679330805 -0600
    committer Reid Priedhorsky <reidpr@lanl.gov> 1679330805 -0600
    data 10
    directory
    from :1
    M 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 foo/bar
    D foo
  It looks to me like the “M ... foo/bar” is being processed before “D foo”
  when it should happen in the opposite order.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.40.0.71.g950264636c cpu: x86_64 built from commit: 950264636c68591989456e3ba0a5442f93152c1a sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 compiler info: gnuc: 10.2 libc info: glibc: 2.31 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]

Thanks, Reid

— he/his

Next: Elijah Newren
Message 1 of 6 in “bug? round-trip through fast-import/fast-export loses files”
  1. Priedhorsky, ReidMar 20, 2023
  2. Elijah NewrenMar 21, 2023
  3. Priedhorsky, ReidMar 21, 2023
  4. Junio C HamanoMar 21, 2023
  5. Jeff KingMar 21, 2023
  6. Elijah NewrenMar 22, 2023

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.