]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/add-p-commentchar-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Jul 2017 20:58:58 +0000 (13:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jul 2017 20:58:59 +0000 (13:58 -0700)
"git add -p" were updated in 2.12 timeframe to cope with custom
core.commentchar but the implementation was buggy and a
metacharacter like $ and * did not work.

* jk/add-p-commentchar-fix:
  add--interactive: quote commentChar regex
  add--interactive: handle EOF in prompt_yesno

1  2 
git-add--interactive.perl
t/t3701-add-interactive.sh

Simple merge
index 2ecb43a61652032862d5a264ede8af473ef345e1,2bfd41f06e4435607760dbe6d78ec72633e46aba..2f3e7cea64e897299d87196135032de22050354b
@@@ -380,101 -380,12 +380,109 @@@ test_expect_success 'patch mode ignore
        test_cmp expected diff
  '
  
 +test_expect_success 'diffs can be colorized' '
 +      git reset --hard &&
 +
 +      # force color even though the test script has no terminal
 +      test_config color.ui always &&
 +
 +      echo content >test &&
 +      printf y | git add -p >output 2>&1 &&
 +
 +      # We do not want to depend on the exact coloring scheme
 +      # git uses for diffs, so just check that we saw some kind of color.
 +      grep "$(printf "\\033")" output
 +'
 +
 +test_expect_success 'patch-mode via -i prompts for files' '
 +      git reset --hard &&
 +
 +      echo one >file &&
 +      echo two >test &&
 +      git add -i <<-\EOF &&
 +      patch
 +      test
 +
 +      y
 +      quit
 +      EOF
 +
 +      echo test >expect &&
 +      git diff --cached --name-only >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'add -p handles globs' '
 +      git reset --hard &&
 +
 +      mkdir -p subdir &&
 +      echo base >one.c &&
 +      echo base >subdir/two.c &&
 +      git add "*.c" &&
 +      git commit -m base &&
 +
 +      echo change >one.c &&
 +      echo change >subdir/two.c &&
 +      git add -p "*.c" <<-\EOF &&
 +      y
 +      y
 +      EOF
 +
 +      cat >expect <<-\EOF &&
 +      one.c
 +      subdir/two.c
 +      EOF
 +      git diff --cached --name-only >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'add -p handles relative paths' '
 +      git reset --hard &&
 +
 +      echo base >relpath.c &&
 +      git add "*.c" &&
 +      git commit -m relpath &&
 +
 +      echo change >relpath.c &&
 +      mkdir -p subdir &&
 +      git -C subdir add -p .. 2>error <<-\EOF &&
 +      y
 +      EOF
 +
 +      test_must_be_empty error &&
 +
 +      cat >expect <<-\EOF &&
 +      relpath.c
 +      EOF
 +      git diff --cached --name-only >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'add -p does not expand argument lists' '
 +      git reset --hard &&
 +
 +      echo content >not-changed &&
 +      git add not-changed &&
 +      git commit -m "add not-changed file" &&
 +
 +      echo change >file &&
 +      GIT_TRACE=$(pwd)/trace.out git add -p . <<-\EOF &&
 +      y
 +      EOF
 +
 +      # we know that "file" must be mentioned since we actually
 +      # update it, but we want to be sure that our "." pathspec
 +      # was not expanded into the argument list of any command.
 +      # So look only for "not-changed".
 +      ! grep not-changed trace.out
 +'
 +
+ test_expect_success 'hunk-editing handles custom comment char' '
+       git reset --hard &&
+       echo change >>file &&
+       test_config core.commentChar "\$" &&
+       echo e | GIT_EDITOR=true git add -p &&
+       git diff --exit-code
+ '
  test_done