From ab58f576bf176cf77638ecda51150260e5f12875 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Thu, 23 Jan 2020 16:47:41 +0000 Subject: [PATCH] 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. --- commands/command_track.go | 19 ++++++++++--------- t/t-track.sh | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/commands/command_track.go b/commands/command_track.go index 3a09d631..1932676d 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -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 diff --git a/t/t-track.sh b/t/t-track.sh index 2b3dfe0b..0b0d655d 100755 --- a/t/t-track.sh +++ b/t/t-track.sh @@ -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