checkout: rewrite path specs on command line
When a user gives a path spec to git lfs checkout on the command line, we turn it into a pattern and then check out only the files specified. However, currently the user can specify a directory and things will work, but in the future, we won't automatically rewrite paths for our file path filter instances. To handle this gracefully, let's rewrite paths that refer to a literal directory as paths referring to every path underneath them. This lets users write "." and get everything in the current directory, which is probably what they wanted.
This commit is contained in:
parent
d452e3a83a
commit
56abb7122a
@ -145,10 +145,10 @@ func whichCheckout() (stage git.IndexStage, err error) {
|
||||
}
|
||||
|
||||
// Parameters are filters
|
||||
// firstly convert any pathspecs to the root of the repo, in case this is being
|
||||
// executed in a sub-folder
|
||||
// firstly convert any pathspecs to patterns relative to the root of the repo,
|
||||
// in case this is being executed in a sub-folder
|
||||
func rootedPaths(args []string) []string {
|
||||
pathConverter, err := lfs.NewCurrentToRepoPathConverter(cfg)
|
||||
pathConverter, err := lfs.NewCurrentToRepoPatternConverter(cfg)
|
||||
if err != nil {
|
||||
Panic(err, "Could not checkout")
|
||||
}
|
||||
|
35
lfs/util.go
35
lfs/util.go
@ -171,6 +171,41 @@ func (p *currentToRepoPathConverter) Convert(filename string) string {
|
||||
return filepath.ToSlash(reltoroot)
|
||||
}
|
||||
|
||||
// Convert filenames expressed relative to the current directory to be relative
|
||||
// to the repo root and convert them into wildmatch patterns.
|
||||
func NewCurrentToRepoPatternConverter(cfg *config.Configuration) (PathConverter, error) {
|
||||
r, c, p, err := pathConverterArgs(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ¤tToRepoPatternConverter{
|
||||
c: ¤tToRepoPathConverter{
|
||||
repoDir: r,
|
||||
currDir: c,
|
||||
passthrough: p,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
type currentToRepoPatternConverter struct {
|
||||
c *currentToRepoPathConverter
|
||||
}
|
||||
|
||||
func (p *currentToRepoPatternConverter) Convert(filename string) string {
|
||||
pattern := p.c.Convert(filename)
|
||||
if st, err := os.Stat(filename); err == nil && st.IsDir() {
|
||||
pattern += "/"
|
||||
}
|
||||
if strings.HasPrefix(pattern, "./") {
|
||||
pattern = pattern[2:]
|
||||
if len(pattern) == 0 {
|
||||
pattern = "**"
|
||||
}
|
||||
}
|
||||
return pattern
|
||||
}
|
||||
|
||||
func pathConverterArgs(cfg *config.Configuration) (string, string, bool, error) {
|
||||
currDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user