From 7d1045d99df6b1237a390a579c62476adb0c76ac Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 1 Jul 2017 21:21:58 -0700 Subject: [PATCH] git lfs status --json only includes lfs files --- commands/command_status.go | 27 ++++++++++++++++++--------- test/test-status.sh | 8 ++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/commands/command_status.go b/commands/command_status.go index e74e26b5..76c47ab8 100644 --- a/commands/command_status.go +++ b/commands/command_status.go @@ -30,11 +30,18 @@ func statusCommand(cmd *cobra.Command, args []string) { scanIndexAt = git.RefBeforeFirstCommit } + scanner, err := lfs.NewPointerScanner() + if err != nil { + scanner.Close() + + ExitWithError(err) + } + if porcelain { porcelainStagedPointers(scanIndexAt) return } else if statusJson { - jsonStagedPointers(scanIndexAt) + jsonStagedPointers(scanner, scanIndexAt) return } @@ -45,13 +52,6 @@ func statusCommand(cmd *cobra.Command, args []string) { ExitWithError(err) } - scanner, err := lfs.NewPointerScanner() - if err != nil { - scanner.Close() - - ExitWithError(err) - } - Print("\nGit LFS objects to be committed:\n") for _, entry := range staged { switch entry.Status { @@ -238,7 +238,7 @@ type JSONStatus struct { Files map[string]JSONStatusEntry `json:"files"` } -func jsonStagedPointers(ref string) { +func jsonStagedPointers(scanner *lfs.PointerScanner, ref string) { staged, unstaged, err := scanIndex(ref) if err != nil { ExitWithError(err) @@ -247,6 +247,15 @@ func jsonStagedPointers(ref string) { status := JSONStatus{Files: make(map[string]JSONStatusEntry)} for _, entry := range append(unstaged, staged...) { + _, fromSrc, err := blobInfoFrom(scanner, entry) + if err != nil { + ExitWithError(err) + } + + if fromSrc != "LFS" { + continue + } + switch entry.Status { case lfs.StatusRename, lfs.StatusCopy: status.Files[entry.DstName] = JSONStatusEntry{ diff --git a/test/test-status.sh b/test/test-status.sh index 263a9447..0724ad81 100755 --- a/test/test-status.sh +++ b/test/test-status.sh @@ -108,6 +108,14 @@ begin_test "status --json" expected='{"files":{"file2.dat":{"status":"R","from":"file1.dat"}}}' [ "$expected" = "$(git lfs status --json)" ] + + git commit -m "file1.dat -> file2.dat" + + # Ensure status --json does not include non-lfs files + echo hi > test1.txt + git add test1.txt + expected='{"files":{}}' + [ "$expected" = "$(git lfs status --json)" ] ) end_test