From 16664b56a97dc48fabf8fcbcab44f58c12bd2f01 Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Tue, 7 Feb 2017 10:33:58 -0700 Subject: [PATCH 1/2] commands: teach track how to handle empty lines in .gitattributes --- commands/command_track.go | 4 ++++ test/test-track.sh | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/commands/command_track.go b/commands/command_track.go index 6fbe6000..daabce29 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -119,6 +119,10 @@ ArgsLoop: for scanner.Scan() { line := scanner.Text() fields := strings.Fields(line) + if len(fields) < 1 { + continue + } + pattern := fields[0] if newline, ok := changedAttribLines[pattern]; ok { // Replace this line (newline already embedded) diff --git a/test/test-track.sh b/test/test-track.sh index c518129d..dc23d8ae 100755 --- a/test/test-track.sh +++ b/test/test-track.sh @@ -12,6 +12,13 @@ begin_test "track" cd track git init + echo "############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +#*.cs diff=csharp" > .gitattributes + # track *.jpg once git lfs track "*.jpg" | grep "Tracking \*.jpg" assert_attributes_count "jpg" "filter=lfs" 1 @@ -374,4 +381,3 @@ begin_test "track lockable read-only/read-write" ) end_test - From b01cb57ce728997106b07b4040ba0552b88b9190 Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Tue, 7 Feb 2017 10:40:25 -0700 Subject: [PATCH 2/2] test: assert that existing gitattributes lines are not clobbered --- test/test-track.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/test-track.sh b/test/test-track.sh index dc23d8ae..8f59bc44 100755 --- a/test/test-track.sh +++ b/test/test-track.sh @@ -33,12 +33,18 @@ begin_test "track" echo "*.gif filter=lfs -text" > a/.gitattributes echo "*.png filter=lfs -text" > a/b/.gitattributes - out=$(git lfs track) - 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"))" - echo "$out" | grep "*.png ($(native_path_escaped "a/b/.gitattributes"))" + git lfs track | tee track.log + grep "Listing tracked patterns" track.log + grep "*.mov ($(native_path_escaped ".git/info/attributes"))" track.log + grep "*.jpg (.gitattributes)" track.log + grep "*.gif ($(native_path_escaped "a/.gitattributes"))" track.log + grep "*.png ($(native_path_escaped "a/b/.gitattributes"))" track.log + + grep "Set default behavior" .gitattributes + grep "############" .gitattributes + grep "* text=auto" .gitattributes + grep "diff=csharp" .gitattributes + grep "*.jpg" .gitattributes ) end_test