commands/status: show partially staged files twice

This commit is contained in:
Taylor Blau 2017-03-22 11:01:55 -06:00
parent cabe0f3f5b
commit 559fb53585
2 changed files with 61 additions and 14 deletions

@ -2,6 +2,7 @@ package commands
import (
"fmt"
"strings"
"github.com/git-lfs/git-lfs/git"
"github.com/git-lfs/git-lfs/lfs"
@ -66,8 +67,9 @@ func scanIndex(ref string) (staged, unstaged []*lfs.DiffIndexEntry, err error) {
seenNames := make(map[string]struct{}, 0)
for _, scanner := range []*lfs.DiffIndexScanner{
uncached, cached,
for scanner, to := range map[*lfs.DiffIndexScanner]*[]*lfs.DiffIndexEntry{
cached: &staged,
uncached: &unstaged,
} {
for scanner.Scan() {
entry := scanner.Entry()
@ -76,16 +78,12 @@ func scanIndex(ref string) (staged, unstaged []*lfs.DiffIndexEntry, err error) {
if len(name) == 0 {
name = entry.SrcName
}
key := strings.Join([]string{entry.SrcSha, entry.DstSha, name}, ":")
if _, seen := seenNames[name]; !seen {
switch entry.Status {
case lfs.StatusModification:
unstaged = append(unstaged, entry)
default:
staged = append(staged, entry)
}
if _, seen := seenNames[key]; !seen {
*to = append(*to, entry)
seenNames[name] = struct{}{}
seenNames[key] = struct{}{}
}
}
@ -131,8 +129,19 @@ func porcelainStagedPointers(ref string) {
ExitWithError(err)
}
seenNames := make(map[string]struct{})
for _, entry := range append(unstaged, staged...) {
Print(porcelainStatusLine(entry))
name := entry.DstName
if len(name) == 0 {
name = entry.SrcName
}
if _, seen := seenNames[name]; !seen {
Print(porcelainStatusLine(entry))
seenNames[name] = struct{}{}
}
}
}

@ -32,7 +32,8 @@ Git LFS objects to be committed:
Git LFS objects not staged for commit:
file1.dat"
file1.dat
file3.dat"
[ "$expected" = "$(git lfs status)" ]
)
@ -60,8 +61,8 @@ begin_test "status --porcelain"
echo "file3 other data" > file3.dat
expected=" M file1.dat
A file2.dat
A file3.dat"
A file3.dat
A file2.dat"
[ "$expected" = "$(git lfs status --porcelain)" ]
)
@ -132,3 +133,40 @@ begin_test "status shows multiple files with identical contents"
[ "1" -eq "$(grep -c "b.dat" status.log)" ]
)
end_test
begin_test "status shows multiple copies of partially staged files"
(
set -e
reponame="status-partially-staged"
git init "$reponame"
cd "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
contents_1="part 1"
printf "$contents_1" > a.dat
# "$contents_1" changes are staged
git add a.dat
# "$contents_2" changes are unstaged
contents_2="part 2"
printf "$contents_2" >> a.dat
expected="On branch master
Git LFS objects to be committed:
a.dat
Git LFS objects not staged for commit:
a.dat"
actual="$(git lfs status)"
diff -u <(echo "$expected") <(echo "$actual")
)
end_test