From 405eaaf99287a73922d2f7bf55f457d3c24aacb7 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 1 Jul 2016 15:52:11 -0600 Subject: [PATCH] commands/track: ignore blacklisted paths by glob and name --- commands/command_track.go | 19 +++++++++++++++++++ test/test-track.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/commands/command_track.go b/commands/command_track.go index b66f643b..6c49eaf0 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -17,6 +17,10 @@ import ( ) var ( + blacklistedTrackArguments = []string{ + ".gitattributes", // TODO + } + trackCmd = &cobra.Command{ Use: "track", Run: trackCommand, @@ -67,6 +71,11 @@ func trackCommand(cmd *cobra.Command, args []string) { ArgsLoop: for _, pattern := range args { + if forbidden := isBlacklisted(pattern); forbidden != "" { + Print("Pattern %s matches forbidden file %s. If you would like to track %s, modify .gitattributes manually.", pattern, forbidden, forbidden) + continue + } + for _, known := range knownPaths { if known.Path == filepath.Join(relpath, pattern) { Print("%s already supported", pattern) @@ -181,6 +190,16 @@ func needsTrailingLinebreak(filename string) bool { return !strings.HasSuffix(string(buf[0:bytesRead]), "\n") } +func isBlacklisted(pattern string) string { + for _, b := range blacklistedTrackArguments { + if matched, _ := filepath.Match(pattern, b); matched { + return b + } + } + + return "" +} + func init() { RootCmd.AddCommand(trackCmd) } diff --git a/test/test-track.sh b/test/test-track.sh index 777281fd..57d34e6a 100755 --- a/test/test-track.sh +++ b/test/test-track.sh @@ -220,3 +220,32 @@ begin_test "track in symlinked dir" } ) end_test + +begin_test "track blacklisted files by name" +( + set -e + + repo="track_blacklisted_by_name" + mkdir "$repo" + cd "$repo" + git init + + git lfs track .gitattributes 2>&1 > track.log + grep "Pattern .gitattributes matches forbidden file .gitattributes" track.log +) +end_test + +begin_test "track blacklisted files with glob" +( + set -e + + repo="track_blacklisted_glob" + mkdir "$repo" + cd "$repo" + git init + + git lfs track ".git*" 2>&1 > track.log + grep "Pattern .git\* matches forbidden file" track.log +) +end_test +