]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'pw/add-p-recount'
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Mar 2018 19:01:04 +0000 (12:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Mar 2018 19:01:04 +0000 (12:01 -0700)
"git add -p" has been lazy in coalescing split patches before
passing the result to underlying "git apply", leading to corner
case bugs; the logic to prepare the patch to be applied after hunk
selections has been tightened.

* pw/add-p-recount:
  add -p: don't rely on apply's '--recount' option
  add -p: fix counting when splitting and coalescing
  add -p: calculate offset delta for edited patches
  add -p: adjust offsets of subsequent hunks when one is skipped
  t3701: add failing test for pathological context lines
  t3701: don't hard code sha1 hash values
  t3701: use test_write_lines and write_script
  t3701: indent here documents
  add -i: add function to format hunk header

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

Simple merge
index 058698df6a4a9811b9db84fb5900472c47c61798,e5c66f750087fc9938b527c447bc814cbab48506..a9a9478a293f97920c6e3fb6d31653d8b37989a6
@@@ -493,52 -498,34 +498,82 @@@ test_expect_success 'add -p works even 
        test_cmp expect actual
  '
  
 +test_expect_success 'setup different kinds of dirty submodules' '
 +      test_create_repo for-submodules &&
 +      (
 +              cd for-submodules &&
 +              test_commit initial &&
 +              test_create_repo dirty-head &&
 +              (
 +                      cd dirty-head &&
 +                      test_commit initial
 +              ) &&
 +              cp -R dirty-head dirty-otherwise &&
 +              cp -R dirty-head dirty-both-ways &&
 +              git add dirty-head &&
 +              git add dirty-otherwise dirty-both-ways &&
 +              git commit -m initial &&
 +
 +              cd dirty-head &&
 +              test_commit updated &&
 +              cd ../dirty-both-ways &&
 +              test_commit updated &&
 +              echo dirty >>initial &&
 +              : >untracked &&
 +              cd ../dirty-otherwise &&
 +              echo dirty >>initial &&
 +              : >untracked
 +      ) &&
 +      git -C for-submodules diff-files --name-only >actual &&
 +      cat >expected <<-\EOF &&
 +      dirty-both-ways
 +      dirty-head
 +      dirty-otherwise
 +      EOF
 +      test_cmp expected actual &&
 +      git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
 +      cat >expected <<-\EOF &&
 +      dirty-both-ways
 +      dirty-head
 +      EOF
 +      test_cmp expected actual
 +'
 +
 +test_expect_success 'status ignores dirty submodules (except HEAD)' '
 +      git -C for-submodules add -i </dev/null >output &&
 +      grep dirty-head output &&
 +      grep dirty-both-ways output &&
 +      ! grep dirty-otherwise output
 +'
 +
+ test_expect_success 'set up pathological context' '
+       git reset --hard &&
+       test_write_lines a a a a a a a a a a a >a &&
+       git add a &&
+       git commit -m a &&
+       test_write_lines c b a a a a a a a b a a a a >a &&
+       test_write_lines     a a a a a a a b a a a a >expected-1 &&
+       test_write_lines   b a a a a a a a b a a a a >expected-2 &&
+       # check editing can cope with missing header and deleted context lines
+       # as well as changes to other lines
+       test_write_lines +b " a" >patch
+ '
+ test_expect_success 'add -p works with pathological context lines' '
+       git reset &&
+       printf "%s\n" n y |
+       git add -p &&
+       git cat-file blob :a >actual &&
+       test_cmp expected-1 actual
+ '
+ test_expect_success 'add -p patch editing works with pathological context lines' '
+       git reset &&
+       # n q q below is in case edit fails
+       printf "%s\n" e y    n q q |
+       git add -p &&
+       git cat-file blob :a >actual &&
+       test_cmp expected-2 actual
+ '
  test_done