commands: don't honor lfs.fetch* for ls-files

Currently, if a user runs git lfs ls-files with lfs.fetchexclude set to
*, then all files are excluded from the output.  This doesn't make much
sense, since the lfs.fetchinclude and lfs.fetchexclude options are
documented to work only on fetches.  Let's ensure that we don't load the
fetch filters by default when performing a non-fetch operation so that
git lfs ls-files isn't affected by these exclusions.
This commit is contained in:
brian m. carlson 2020-03-27 19:02:58 +00:00
parent 43ac6cfb21
commit 0245ce5aa6
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
8 changed files with 46 additions and 13 deletions

@ -79,7 +79,7 @@ func cloneCommand(cmd *cobra.Command, args []string) {
if ref, err := git.CurrentRef(); err == nil {
includeArg, excludeArg := getIncludeExcludeArgs(cmd)
filter := buildFilepathFilter(cfg, includeArg, excludeArg)
filter := buildFilepathFilter(cfg, includeArg, excludeArg, true)
if cloneFlags.NoCheckout || cloneFlags.Bare {
// If --no-checkout or --bare then we shouldn't check out, just fetch instead
fetchRef(ref.Name, filter)

@ -88,7 +88,7 @@ func fetchCommand(cmd *cobra.Command, args []string) {
}
} else { // !all
filter := buildFilepathFilter(cfg, include, exclude)
filter := buildFilepathFilter(cfg, include, exclude, true)
// Fetch refs sequentially per arg order; duplicates in later refs will be ignored
for _, ref := range refs {

@ -107,7 +107,7 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
defer gitscanner.Close()
includeArg, excludeArg := getIncludeExcludeArgs(cmd)
gitscanner.Filter = buildFilepathFilter(cfg, includeArg, excludeArg)
gitscanner.Filter = buildFilepathFilter(cfg, includeArg, excludeArg, false)
if len(args) == 0 {
// Only scan the index when "git lfs ls-files" was invoked with

@ -303,7 +303,7 @@ func currentRefToMigrate() (*git.Ref, error) {
// filter given by the --include and --exclude arguments.
func getHistoryRewriter(cmd *cobra.Command, db *gitobj.ObjectDatabase, l *tasklog.Logger) *githistory.Rewriter {
include, exclude := getIncludeExcludeArgs(cmd)
filter := buildFilepathFilter(cfg, include, exclude)
filter := buildFilepathFilter(cfg, include, exclude, false)
return githistory.NewRewriter(db,
githistory.WithFilter(filter), githistory.WithLogger(l))

@ -27,7 +27,7 @@ func pullCommand(cmd *cobra.Command, args []string) {
}
includeArg, excludeArg := getIncludeExcludeArgs(cmd)
filter := buildFilepathFilter(cfg, includeArg, excludeArg)
filter := buildFilepathFilter(cfg, includeArg, excludeArg, true)
pull(filter)
}

@ -126,8 +126,8 @@ func currentRemoteRef() *git.Ref {
return git.NewRefUpdate(cfg.Git, cfg.PushRemote(), cfg.CurrentRef(), nil).Right()
}
func buildFilepathFilter(config *config.Configuration, includeArg, excludeArg *string) *filepathfilter.Filter {
inc, exc := determineIncludeExcludePaths(config, includeArg, excludeArg)
func buildFilepathFilter(config *config.Configuration, includeArg, excludeArg *string, useFetchOptions bool) *filepathfilter.Filter {
inc, exc := determineIncludeExcludePaths(config, includeArg, excludeArg, useFetchOptions)
return filepathfilter.New(inc, exc)
}
@ -449,14 +449,22 @@ func logPanicToWriter(w io.Writer, loggedError error, le string) {
}
}
func determineIncludeExcludePaths(config *config.Configuration, includeArg, excludeArg *string) (include, exclude []string) {
func determineIncludeExcludePaths(config *config.Configuration, includeArg, excludeArg *string, useFetchOptions bool) (include, exclude []string) {
if includeArg == nil {
include = config.FetchIncludePaths()
if useFetchOptions {
include = config.FetchIncludePaths()
} else {
include = []string{}
}
} else {
include = tools.CleanPaths(*includeArg, ",")
}
if excludeArg == nil {
exclude = config.FetchExcludePaths()
if useFetchOptions {
exclude = config.FetchExcludePaths()
} else {
exclude = []string{}
}
} else {
exclude = tools.CleanPaths(*excludeArg, ",")
}

@ -19,7 +19,7 @@ var (
func TestDetermineIncludeExcludePathsReturnsCleanedPaths(t *testing.T) {
inc := "/some/include"
exc := "/some/exclude"
i, e := determineIncludeExcludePaths(testcfg, &inc, &exc)
i, e := determineIncludeExcludePaths(testcfg, &inc, &exc, true)
assert.Equal(t, []string{"/some/include"}, i)
assert.Equal(t, []string{"/some/exclude"}, e)
@ -28,15 +28,22 @@ func TestDetermineIncludeExcludePathsReturnsCleanedPaths(t *testing.T) {
func TestDetermineIncludeExcludePathsReturnsEmptyPaths(t *testing.T) {
inc := ""
exc := ""
i, e := determineIncludeExcludePaths(testcfg, &inc, &exc)
i, e := determineIncludeExcludePaths(testcfg, &inc, &exc, true)
assert.Empty(t, i)
assert.Empty(t, e)
}
func TestDetermineIncludeExcludePathsReturnsDefaultsWhenAbsent(t *testing.T) {
i, e := determineIncludeExcludePaths(testcfg, nil, nil)
i, e := determineIncludeExcludePaths(testcfg, nil, nil, true)
assert.Equal(t, []string{"/default/include"}, i)
assert.Equal(t, []string{"/default/exclude"}, e)
}
func TestDetermineIncludeExcludePathsReturnsNothingWhenAbsent(t *testing.T) {
i, e := determineIncludeExcludePaths(testcfg, nil, nil, false)
assert.Empty(t, i)
assert.Empty(t, e)
}

@ -497,4 +497,22 @@ begin_test "ls-files: history with reference range"
[ 0 -eq $(grep -c "b\.dat" ls-files.log) ]
[ 0 -eq $(grep -c "c\.dat" ls-files.log) ]
)
end_test
begin_test "ls-files: not affected by lfs.fetchexclude"
(
set -e
mkdir repo-fetchexclude
cd repo-fetchexclude
git init
git lfs track "*.dat" | grep "Tracking \"\*.dat\""
echo "some data" > some.dat
echo "some text" > some.txt
echo "missing" > missing.dat
git add missing.dat
git commit -m "add missing file"
git config lfs.fetchexclude '*'
[ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ]
)
end_test