command/status: handle deleted files gracefully

If a had a file (either Git LFS or plain Git) that was deleted with git
rm but not yet committed, git lfs status would produce an error
indicating that the file could not be opened. Since this is not helpful,
if the user has deleted the file, instead indicate this by showing that
the behavior to be committed is a file deletion.

Note that we will only traverse this code path when the destination Git
hash is all zeros (indicating a deleted or missing file).
This commit is contained in:
brian m. carlson 2019-01-17 17:43:55 +00:00
parent 561063559f
commit b472289031
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
2 changed files with 42 additions and 0 deletions

@ -145,6 +145,9 @@ func blobInfo(s *lfs.PointerScanner, blobSha, name string) (sha, from string, er
} }
f, err := os.Open(filepath.Join(cfg.LocalWorkingDir(), name)) f, err := os.Open(filepath.Join(cfg.LocalWorkingDir(), name))
if os.IsNotExist(err) {
return "deleted", "File", nil
}
if err != nil { if err != nil {
return "", "", err return "", "", err
} }

@ -464,3 +464,42 @@ begin_test "status (without a working copy)"
[ "This operation must be run in a work tree." = "$(cat status.log)" ] [ "This operation must be run in a work tree." = "$(cat status.log)" ]
) )
end_test end_test
begin_test "status (deleted files)"
(
set -e
reponame="status-deleted-files"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
git push origin master
contents="a"
oid="$(calc_oid "$contents")"
oid_short="$(calc_oid "$contents" | head -c 7)"
printf "%s" "$contents" > a.dat
git add a.dat
git commit -m "add a large file"
git rm a.dat
expected="On branch master
Git LFS objects to be pushed to origin/master:
a.dat ($oid)
Git LFS objects to be committed:
a.dat (LFS: $oid_short -> File: deleted)
Git LFS objects not staged for commit:"
[ "$expected" = "$(git lfs status)" ]
)
end_test