ls-files show duplicate with OID(s)
This commit is contained in:
parent
9f88f2fc52
commit
21bc33e8c0
@ -1,12 +1,15 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/github/git-lfs/git"
|
||||
"github.com/github/git-lfs/lfs"
|
||||
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
longOIDs = false
|
||||
lsFilesCmd = &cobra.Command{
|
||||
Use: "ls-files",
|
||||
Run: lsFilesCommand,
|
||||
@ -29,6 +32,11 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
|
||||
ref = fullref.Sha
|
||||
}
|
||||
|
||||
showShaLen := 7
|
||||
if longOIDs {
|
||||
showShaLen = 40
|
||||
}
|
||||
|
||||
scanOpt := &lfs.ScanRefsOptions{SkipDeletedBlobs: true}
|
||||
listFiles := make(map[string][]string)
|
||||
fileTree, err := lfs.ScanTree(ref)
|
||||
@ -44,16 +52,12 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
|
||||
Panic(err, "Could not scan for Git LFS files")
|
||||
}
|
||||
for _, p := range pointers {
|
||||
Print(p.Name)
|
||||
if len(listFiles[p.Sha1]) > 1 {
|
||||
for _, v := range listFiles[p.Sha1][1:] {
|
||||
Print(v + " (duplicate of " + p.Name + ")")
|
||||
}
|
||||
}
|
||||
Print(p.Sha1[0:showShaLen] + " ==> [ " + strings.Join(listFiles[p.Sha1], ",") + " ]")
|
||||
delete(listFiles, p.Sha1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
lsFilesCmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "Show object ID(s) 40 characters")
|
||||
RootCmd.AddCommand(lsFilesCmd)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ begin_test "ls-files"
|
||||
echo "missing" > missing.dat
|
||||
git add missing.dat
|
||||
git commit -m "add missing file"
|
||||
[ "missing.dat" = "$(git lfs ls-files)" ]
|
||||
[ "74f2f1c ==> [ missing.dat ]" = "$(git lfs ls-files)" ]
|
||||
|
||||
git rm missing.dat
|
||||
git add some.dat some.txt
|
||||
@ -70,8 +70,8 @@ begin_test "ls-files: show duplicate files"
|
||||
(
|
||||
set -e
|
||||
|
||||
mkdir dupRepo
|
||||
cd dupRepo
|
||||
mkdir dupRepoShort
|
||||
cd dupRepoShort
|
||||
git init
|
||||
|
||||
git lfs track "*.tgz" | grep "Tracking \*.tgz"
|
||||
@ -80,7 +80,24 @@ begin_test "ls-files: show duplicate files"
|
||||
git add one.tgz
|
||||
git add two.tgz
|
||||
git commit -m "add duplicate files"
|
||||
[ "$(git lfs ls-files)" = "$(printf 'one.tgz\ntwo.tgz (duplicate of one.tgz)')" ]
|
||||
|
||||
[ "67f58a4 ==> [ one.tgz,two.tgz ]" = "$(git lfs ls-files)" ]
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "ls-files: show duplicate files with long OID"
|
||||
(
|
||||
set -e
|
||||
|
||||
mkdir dupRepoLong
|
||||
cd dupRepoLong
|
||||
git init
|
||||
|
||||
git lfs track "*.tgz" | grep "Tracking \*.tgz"
|
||||
echo "test content" > one.tgz
|
||||
echo "test content" > two.tgz
|
||||
git add one.tgz
|
||||
git add two.tgz
|
||||
git commit -m "add duplicate files with long OID"
|
||||
[ "67f58a40df1e32b439f55e722178c337042d2148 ==> [ one.tgz,two.tgz ]" = "$(git lfs ls-files --long)" ]
|
||||
)
|
||||
end_test
|
||||
|
Loading…
Reference in New Issue
Block a user