git lfs status --json only includes lfs files

This commit is contained in:
Anthony Sottile 2017-07-01 21:21:58 -07:00
parent ccb52dd6e0
commit 7d1045d99d
2 changed files with 26 additions and 9 deletions

@ -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{

@ -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