Merge pull request #2374 from asottile/lfs_status_only_lfs
git lfs status --json only includes lfs files
This commit is contained in:
commit
35f6635492
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user