update the code to be consistent with 'pattern' name

This commit is contained in:
risk danger olson 2016-11-10 15:29:17 -07:00
parent 7b87b50cd6
commit 9a803419e9
2 changed files with 17 additions and 18 deletions

@ -42,12 +42,12 @@ func trackCommand(cmd *cobra.Command, args []string) {
}
lfs.InstallHooks(false)
knownPaths := findPaths()
knownPatterns := findPatterns()
if len(args) == 0 {
Print("Listing tracked paths")
for _, t := range knownPaths {
Print(" %s (%s)", t.Path, t.Source)
Print("Listing tracked patterns")
for _, t := range knownPatterns {
Print(" %s (%s)", t.Pattern, t.Source)
}
return
}
@ -61,7 +61,7 @@ func trackCommand(cmd *cobra.Command, args []string) {
defer attributesFile.Close()
if addTrailingLinebreak {
if _, err := attributesFile.WriteString("\n"); err != nil {
if _, werr := attributesFile.WriteString("\n"); werr != nil {
Print("Error writing to .gitattributes")
}
}
@ -75,8 +75,8 @@ func trackCommand(cmd *cobra.Command, args []string) {
ArgsLoop:
for _, unsanitizedPattern := range args {
pattern := cleanRootPath(unsanitizedPattern)
for _, known := range knownPaths {
if known.Path == filepath.Join(relpath, pattern) {
for _, known := range knownPatterns {
if known.Pattern == filepath.Join(relpath, pattern) {
Print("%s already supported", pattern)
continue ArgsLoop
}
@ -119,7 +119,7 @@ ArgsLoop:
encodedArg := strings.Replace(pattern, " ", "[[:space:]]", -1)
_, err := attributesFile.WriteString(fmt.Sprintf("%s filter=lfs diff=lfs merge=lfs -text\n", encodedArg))
if err != nil {
Print("Error adding path %s", pattern)
Print("Error adding pattern %s", pattern)
continue
}
}
@ -142,13 +142,13 @@ ArgsLoop:
}
}
type mediaPath struct {
Path string
Source string
type mediaPattern struct {
Pattern string
Source string
}
func findPaths() []mediaPath {
paths := make([]mediaPath, 0)
func findPatterns() []mediaPattern {
var patterns []mediaPattern
for _, path := range findAttributeFiles() {
attributes, err := os.Open(path)
@ -168,16 +168,16 @@ func findPaths() []mediaPath {
pattern = filepath.Join(reldir, pattern)
}
paths = append(paths, mediaPath{Path: pattern, Source: relfile})
patterns = append(patterns, mediaPattern{Pattern: pattern, Source: relfile})
}
}
}
return paths
return patterns
}
func findAttributeFiles() []string {
paths := make([]string, 0)
var paths []string
repoAttributes := filepath.Join(config.LocalGitDir, "info", "attributes")
if info, err := os.Stat(repoAttributes); err == nil && !info.IsDir() {

@ -37,7 +37,7 @@ begin_test "track"
echo "*.png filter=lfs -text" > a/b/.gitattributes
out=$(git lfs track)
echo "$out" | grep "Listing tracked paths"
echo "$out" | grep "Listing tracked patterns"
echo "$out" | grep "*.mov ($(native_path_escaped ".git/info/attributes"))"
echo "$out" | grep "*.jpg (.gitattributes)"
echo "$out" | grep "*.gif ($(native_path_escaped "a/.gitattributes"))"
@ -292,4 +292,3 @@ begin_test "track blocklisted files with glob"
grep "Pattern .git\* matches forbidden file" track.log
)
end_test