3 # Copyright (c) 2007 Shawn O. Pearce
6 test_description='git apply -p handling.'
9 . "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
11 test_expect_success setup '
14 cp sub/file1 file1.saved &&
17 git diff >patch.file &&
18 git checkout -- sub/file1 &&
21 git diff >patch.escaped &&
22 grep "[\]" patch.escaped &&
27 test_expect_success 'apply git diff with -p2' '
28 cp file1.saved file1 &&
29 git apply -p2 patch.file
32 test_expect_success 'apply with too large -p' '
33 cp file1.saved file1 &&
34 test_must_fail git apply --stat -p3 patch.file 2>err &&
35 grep "removing 3 leading" err
38 test_expect_success 'apply (-p2) traditional diff with funny filenames' '
39 cat >patch.quotes <<-\EOF &&
40 diff -u "a/"sub/file1 "b/"sub/file1
49 cp file1.saved file1 &&
50 git apply -p2 patch.quotes &&
51 test_cmp expected file1
54 test_expect_success 'apply with too large -p and fancy filename' '
55 cp file1.saved file1 &&
56 test_must_fail git apply --stat -p3 patch.escaped 2>err &&
57 grep "removing 3 leading" err
60 test_expect_success 'apply (-p2) diff, mode change only' '
61 cat >patch.chmod <<-\EOF &&
62 diff --git a/sub/file1 b/sub/file1
66 test_chmod -x file1 &&
67 git apply --index -p2 patch.chmod &&
68 case $(git ls-files -s file1) in 100755*) : good;; *) false;; esac
71 test_expect_success FILEMODE 'file mode was changed' '
75 test_expect_success 'apply (-p2) diff, rename' '
76 cat >patch.rename <<-\EOF &&
77 diff --git a/sub/file1 b/sub/file2
84 cp file1.saved file1 &&
86 git apply -p2 patch.rename &&
87 test_cmp expected file2