Skip to content

git-lfs migrate import does not add attributes for copied files (same name and content) #4628

@ycongal-smile

Description

@ycongal-smile

Describe the bug
When trying to git-lfs migrate import a repo in which there are copied files (eg: dirA/file = dirB/file), the .gitattributes file does not list all instances of the file but they are all changed to a pointer blob. This results in a incoherent repo.

To Reproduce
Steps to reproduce the behavior:

  1. Create a test repo with this script :
git init
echo test > a
mkdir dir
cp a dir/
git add a dir/a
git commit -m "add a dir/a"
# In this repo a & dir/a have the same name and content
  1. Import the repo in git-lfs : git lfs migrate import --above=1b
  2. Look at .gitattributes and notice that dir/a is missing
$ cat .gitattributes 
/a filter=lfs diff=lfs merge=lfs -text
  1. Look at dir/a and notice that it is a "LFS pointer blob" :
$ cat dir/a 
version https://git-lfs.github.com/spec/v1
oid sha256:f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
size 5
  1. To go further, doing a git-lfs checkout result in a dirty repo (dir/apointer is replaced by its content but without a filter, so git notices the change)
$ git-lfs checkout
Checking out LFS objects: 100% (2/2), 10 B | 0 B/s, done.                                                                                                                                     
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   dir/a
  1. As a workaround, I can git-lfs track dir/a and commit the resulting modifications.

NB: I can't reproduce this behavior if the name are different (eg a = dir/b)

Expected behavior
After the git lfs migrate import ..., a and dir/aare listed in .gitattributes.

System environment
Tested on a master (commit 16da803) build on a Debian 11 (bullseye).

Output of git lfs env

git-lfs/2.13.0 (GitHub; linux amd64; go 1.15.9)
git version 2.30.2

LocalWorkingDir=$BASE/git-lfs/debug_dir/tmp.1631551057.6tar
LocalGitDir=$BASE/git-lfs/debug_dir/tmp.1631551057.6tar/.git
LocalGitStorageDir=$BASE/git-lfs/debug_dir/tmp.1631551057.6tar/.git
LocalMediaDir=$BASE/git-lfs/debug_dir/tmp.1631551057.6tar/.git/lfs/objects
LocalReferenceDirs=
TempDir=$BASE/git-lfs/debug_dir/tmp.1631551057.6tar/.git/lfs/tmp
ConcurrentTransfers=8
TusTransfers=false
BasicTransfersOnly=false
SkipDownloadErrors=false
FetchRecentAlways=false
FetchRecentRefsDays=7
FetchRecentCommitsDays=0
FetchRecentRefsIncludeRemotes=true
PruneOffsetDays=3
PruneVerifyRemoteAlways=false
PruneRemoteName=origin
LfsStorageDir=$BASE/git-lfs/debug_dir/tmp.1631551057.6tar/.git/lfs
AccessDownload=none
AccessUpload=none
DownloadTransfers=basic,lfs-standalone-file,ssh
UploadTransfers=basic,lfs-standalone-file,ssh
git config filter.lfs.process = "git-lfs filter-process"
git config filter.lfs.smudge = "git-lfs smudge -- %f"
git config filter.lfs.clean = "git-lfs clean -- %f"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions