track: detect duplicate patterns with --filename
When we add a pattern with git lfs track, we inform the user if the pattern is already supported. However, we fail to do so when the --filename argument is passed, due to not having encoded the pattern at that point. To solve this problem, hoist the code that encodes the filename as a pattern so it happens before we check if we already have such a pattern.
This commit is contained in:
parent
a526ba6bf1
commit
ab58f576bf
@ -77,6 +77,16 @@ func trackCommand(cmd *cobra.Command, args []string) {
|
||||
ArgsLoop:
|
||||
for _, unsanitizedPattern := range args {
|
||||
pattern := trimCurrentPrefix(cleanRootPath(unsanitizedPattern))
|
||||
|
||||
// Generate the new / changed attrib line for merging
|
||||
var encodedArg string
|
||||
if trackFilenameFlag {
|
||||
encodedArg = escapeGlobCharacters(pattern)
|
||||
pattern = escapeGlobCharacters(pattern)
|
||||
} else {
|
||||
encodedArg = escapeAttrPattern(pattern)
|
||||
}
|
||||
|
||||
if !trackNoModifyAttrsFlag {
|
||||
for _, known := range knownPatterns {
|
||||
if unescapeAttrPattern(known.Path) == filepath.Join(relpath, pattern) &&
|
||||
@ -89,15 +99,6 @@ ArgsLoop:
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the new / changed attrib line for merging
|
||||
var encodedArg string
|
||||
if trackFilenameFlag {
|
||||
encodedArg = escapeGlobCharacters(pattern)
|
||||
pattern = escapeGlobCharacters(pattern)
|
||||
} else {
|
||||
encodedArg = escapeAttrPattern(pattern)
|
||||
}
|
||||
|
||||
lockableArg := ""
|
||||
if trackLockableFlag { // no need to test trackNotLockableFlag, if we got here we're disabling
|
||||
lockableArg = " " + git.LockableAttrib
|
||||
|
@ -670,6 +670,7 @@ begin_test "track: escaped glob pattern in .gitattributes"
|
||||
contents_oid=$(calc_oid "$contents")
|
||||
|
||||
git lfs track --filename "$filename"
|
||||
git lfs track --filename "$filename" | grep 'already supported'
|
||||
git add .
|
||||
cat .gitattributes
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user