3 # Copyright (c) 2007 Shawn O. Pearce
6 test_description='git apply -p handling.'
10 test_expect_success setup '
13 cp sub/file1 file1.saved &&
16 git diff >patch.file &&
17 git checkout -- sub/file1 &&
20 git diff >patch.escaped &&
21 grep "[\]" patch.escaped &&
26 test_expect_success 'apply git diff with -p2' '
27 cp file1.saved file1 &&
28 git apply -p2 patch.file
31 test_expect_success 'apply with too large -p' '
32 cp file1.saved file1 &&
33 test_must_fail git apply --stat -p3 patch.file 2>err &&
34 grep "removing 3 leading" err
37 test_expect_success 'apply (-p2) traditional diff with funny filenames' '
38 cat >patch.quotes <<-\EOF &&
39 diff -u "a/"sub/file1 "b/"sub/file1
48 cp file1.saved file1 &&
49 git apply -p2 patch.quotes &&
50 test_cmp expected file1
53 test_expect_success 'apply with too large -p and fancy filename' '
54 cp file1.saved file1 &&
55 test_must_fail git apply --stat -p3 patch.escaped 2>err &&
56 grep "removing 3 leading" err
59 test_expect_success 'apply (-p2) diff, mode change only' '
60 cat >patch.chmod <<-\EOF &&
61 diff --git a/sub/file1 b/sub/file1
66 git apply -p2 patch.chmod &&
70 test_expect_success 'apply (-p2) diff, rename' '
71 cat >patch.rename <<-\EOF &&
72 diff --git a/sub/file1 b/sub/file2
79 cp file1.saved file1 &&
81 git apply -p2 patch.rename &&
82 test_cmp expected file2