Skip to content

Commit 21bc33e

Browse files
aorjoatechnoweenie
authored andcommitted
ls-files show duplicate with OID(s)
1 parent 9f88f2f commit 21bc33e

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

commands/command_ls_files.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package commands
22

33
import (
4+
"strings"
5+
46
"github.com/github/git-lfs/git"
57
"github.com/github/git-lfs/lfs"
68
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
79
)
810

911
var (
12+
longOIDs = false
1013
lsFilesCmd = &cobra.Command{
1114
Use: "ls-files",
1215
Run: lsFilesCommand,
@@ -29,6 +32,11 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
2932
ref = fullref.Sha
3033
}
3134

35+
showShaLen := 7
36+
if longOIDs {
37+
showShaLen = 40
38+
}
39+
3240
scanOpt := &lfs.ScanRefsOptions{SkipDeletedBlobs: true}
3341
listFiles := make(map[string][]string)
3442
fileTree, err := lfs.ScanTree(ref)
@@ -44,16 +52,12 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
4452
Panic(err, "Could not scan for Git LFS files")
4553
}
4654
for _, p := range pointers {
47-
Print(p.Name)
48-
if len(listFiles[p.Sha1]) > 1 {
49-
for _, v := range listFiles[p.Sha1][1:] {
50-
Print(v + " (duplicate of " + p.Name + ")")
51-
}
52-
}
55+
Print(p.Sha1[0:showShaLen] + " ==> [ " + strings.Join(listFiles[p.Sha1], ",") + " ]")
5356
delete(listFiles, p.Sha1)
5457
}
5558
}
5659

5760
func init() {
61+
lsFilesCmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "Show object ID(s) 40 characters")
5862
RootCmd.AddCommand(lsFilesCmd)
5963
}

test/test-ls-files.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ begin_test "ls-files"
1515
echo "missing" > missing.dat
1616
git add missing.dat
1717
git commit -m "add missing file"
18-
[ "missing.dat" = "$(git lfs ls-files)" ]
18+
[ "74f2f1c ==> [ missing.dat ]" = "$(git lfs ls-files)" ]
1919

2020
git rm missing.dat
2121
git add some.dat some.txt
@@ -70,8 +70,8 @@ begin_test "ls-files: show duplicate files"
7070
(
7171
set -e
7272

73-
mkdir dupRepo
74-
cd dupRepo
73+
mkdir dupRepoShort
74+
cd dupRepoShort
7575
git init
7676

7777
git lfs track "*.tgz" | grep "Tracking \*.tgz"
@@ -80,7 +80,24 @@ begin_test "ls-files: show duplicate files"
8080
git add one.tgz
8181
git add two.tgz
8282
git commit -m "add duplicate files"
83-
[ "$(git lfs ls-files)" = "$(printf 'one.tgz\ntwo.tgz (duplicate of one.tgz)')" ]
83+
[ "67f58a4 ==> [ one.tgz,two.tgz ]" = "$(git lfs ls-files)" ]
84+
)
85+
end_test
86+
87+
begin_test "ls-files: show duplicate files with long OID"
88+
(
89+
set -e
90+
91+
mkdir dupRepoLong
92+
cd dupRepoLong
93+
git init
8494

95+
git lfs track "*.tgz" | grep "Tracking \*.tgz"
96+
echo "test content" > one.tgz
97+
echo "test content" > two.tgz
98+
git add one.tgz
99+
git add two.tgz
100+
git commit -m "add duplicate files with long OID"
101+
[ "67f58a40df1e32b439f55e722178c337042d2148 ==> [ one.tgz,two.tgz ]" = "$(git lfs ls-files --long)" ]
85102
)
86103
end_test

0 commit comments

Comments
 (0)