Merge pull request #3219 from git-lfs/ttaylorr/ls-files-no-index

commands/command_ls_files.go: ignore index with argument
This commit is contained in:
Taylor Blau 2018-09-05 15:25:27 -04:00 committed by GitHub
commit 63d7ca608d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 3 deletions

@ -26,7 +26,16 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
if len(args) == 1 {
if lsFilesScanAll {
Exit("fatal: cannot use --all with explicit reference")
} else if args[0] == "--all" {
// Since --all is a valid argument to "git rev-parse",
// if we try to give it to git.ResolveRef below, we'll
// get an unexpected result.
//
// So, let's check early that the caller invoked the
// command correctly.
Exit("fatal: did you mean \"git lfs ls-files --all --\" ?")
}
ref = args[0]
} else {
fullref, err := git.CurrentRef()
@ -88,8 +97,15 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
includeArg, excludeArg := getIncludeExcludeArgs(cmd)
gitscanner.Filter = buildFilepathFilter(cfg, includeArg, excludeArg)
if err := gitscanner.ScanIndex(ref, nil); err != nil {
Exit("Could not scan for Git LFS index: %s", err)
if len(args) == 0 {
// Only scan the index when "git lfs ls-files" was invoked with
// no arguments.
//
// Do so to avoid showing "mixed" results, e.g., ls-files output
// from a specific historical revision, and the index.
if err := gitscanner.ScanIndex(ref, nil); err != nil {
Exit("Could not scan for Git LFS index: %s", err)
}
}
if lsFilesScanAll {
if err := gitscanner.ScanAll(nil); err != nil {

@ -113,6 +113,62 @@ begin_test "ls-files: indexed file with tree"
)
end_test
begin_test "ls-files: historical reference ignores index"
(
set -e
reponame="ls-files-historical-reference-ignores-index"
git init "$reponame"
cd "$reponame"
git lfs track "*.txt"
echo "a.txt" > a.txt
echo "b.txt" > b.txt
echo "c.txt" > c.txt
git add .gitattributes a.txt
git commit -m "a.txt: initial commit"
git add b.txt
git commit -m "b.txt: initial commit"
git add c.txt
git lfs ls-files "$(git rev-parse HEAD~1)" 2>&1 | tee ls-files.log
[ 1 -eq "$(grep -c "a.txt" ls-files.log)" ]
[ 0 -eq "$(grep -c "b.txt" ls-files.log)" ]
[ 0 -eq "$(grep -c "c.txt" ls-files.log)" ]
)
end_test
begin_test "ls-files: non-HEAD reference referring to HEAD ignores index"
(
set -e
reponame="ls-files-HEAD-ish-ignores-index"
git init "$reponame"
cd "$reponame"
git lfs track "*.txt"
echo "a.txt" > a.txt
echo "b.txt" > b.txt
git add .gitattributes a.txt
git commit -m "a.txt: initial commit"
tagname="v1.0.0"
git tag "$tagname"
git add b.txt
git lfs ls-files "$tagname" 2>&1 | tee ls-files.log
[ 1 -eq "$(grep -c "a.txt" ls-files.log)" ]
[ 0 -eq "$(grep -c "b.txt" ls-files.log)" ]
)
end_test
begin_test "ls-files: outside git repository"
(
set +e
@ -326,7 +382,7 @@ begin_test "ls-files: invalid --all ordering"
echo >&2 "fatal: expected \`git lfs ls-files -- --all\' to fail"
exit 1
fi
grep "Could not scan for Git LFS tree" ls-files.out
grep "fatal: did you mean \"git lfs ls-files --all --\" ?" ls-files.out
)
end_test