From b472289031a08ef2b1424f4284d652ca1432f980 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Thu, 17 Jan 2019 17:43:55 +0000 Subject: [PATCH] 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). --- commands/command_status.go | 3 +++ t/t-status.sh | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/commands/command_status.go b/commands/command_status.go index 60af1e60..300003dc 100644 --- a/commands/command_status.go +++ b/commands/command_status.go @@ -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)) + if os.IsNotExist(err) { + return "deleted", "File", nil + } if err != nil { return "", "", err } diff --git a/t/t-status.sh b/t/t-status.sh index b55194b3..c4cd834f 100755 --- a/t/t-status.sh +++ b/t/t-status.sh @@ -464,3 +464,42 @@ begin_test "status (without a working copy)" [ "This operation must be run in a work tree." = "$(cat status.log)" ] ) 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