You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#416 Fix - Files of the same name in sub-folders will be considered a… (#455)
* #416 Fix - Files of the same name in sub-folders will be considered as different files
* #416 Fix - Adding more testcases and covering all possible special characters
---------
Co-authored-by: Owen Nelson <58788812+tw-owen-nelson@users.noreply.github.com>
//AdditionsWithinRange returns the outgoing additions and modifications in a GitRepo that are in the given commit range. This does not include files that were deleted.
144
+
//AdditionsWithinRange returns the outgoing additions and modifications in a GitRepo that are in the given commit range. This does not include files that were deleted.
//Matches states whether the addition matches the given pattern.
191
-
//If the pattern ends in a path separator, then all files inside a directory with that name are matched. However, files with that name itself will not be matched.
192
-
//If a pattern contains the path separator in any other location, the match works according to the pattern logic of the default golang glob mechanism
193
-
//If there is no path separator anywhere in the pattern, the pattern is matched against the base name of the file. Thus, the pattern will match files with that name anywhere in the repository.
190
+
// Matches states whether the addition matches the given pattern.
191
+
// If the pattern ends in a path separator, then all files inside a directory with that name are matched. However, files with that name itself will not be matched.
192
+
// If a pattern contains the path separator in any other location, the match works according to the pattern logic of the default golang glob mechanism
193
+
// If there are other special characters in the pattern, the pattern is matched against the base name of the file. Thus, the pattern will match files with that pattern anywhere in the repository.
194
+
// If there are no special characters in the pattern, then it means exact filename is provided as pattern like file.txt. Thus, the pattern is matched against the file path so that not all files with the same name in the repo are not returned.
194
195
func (aAddition) Matches(patternstring) bool {
195
196
varresultbool
196
-
ifpattern[len(pattern)-1] =='/' {
197
+
ifpattern[len(pattern)-1] =='/' {// If the pattern ends in a path separator, then all files inside a directory with that name are matched. However, files with that name itself will not be matched.
197
198
result=strings.HasPrefix(string(a.Path), pattern)
198
-
} elseifstrings.ContainsRune(pattern, '/') {
199
+
} elseifstrings.ContainsRune(pattern, '/') {// If a pattern contains the path separator in any other location, the match works according to the pattern logic of the default golang glob mechanism
199
200
result, _=path.Match(pattern, string(a.Path))
200
-
} else{
201
+
} elseifstrings.ContainsAny(pattern, "*?[]\\") { // If there are other special characters in the pattern, the pattern is matched against the base name of the file. Thus, the pattern will match files with that pattern anywhere in the repository.
201
202
result, _=path.Match(pattern, string(a.Name))
203
+
} else { // If there are no special characters in the pattern, then it means exact filename is provided as pattern like file.txt. Thus, the pattern is matched against the file path so that not all files with the same name in the repo are not returned.
0 commit comments