]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4120-apply-popt.sh
t3509: use unconstrained initial test to setup repository.
[thirdparty/git.git] / t / t4120-apply-popt.sh
CommitLineData
79ee194e
SP
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn O. Pearce
4#
5
5be60078 6test_description='git apply -p handling.'
79ee194e
SP
7
8. ./test-lib.sh
9
10test_expect_success setup '
11 mkdir sub &&
12 echo A >sub/file1 &&
bb7306b5 13 cp sub/file1 file1.saved &&
79ee194e
SP
14 git add sub/file1 &&
15 echo B >sub/file1 &&
16 git diff >patch.file &&
bb7306b5
JN
17 git checkout -- sub/file1 &&
18 git mv sub süb &&
19 echo B >süb/file1 &&
20 git diff >patch.escaped &&
21 grep "[\]" patch.escaped &&
22 rm süb/file1 &&
23 rmdir süb
79ee194e
SP
24'
25
26test_expect_success 'apply git diff with -p2' '
bb7306b5 27 cp file1.saved file1 &&
79ee194e
SP
28 git apply -p2 patch.file
29'
30
15862087 31test_expect_success 'apply with too large -p' '
bb7306b5 32 cp file1.saved file1 &&
15862087
AG
33 test_must_fail git apply --stat -p3 patch.file 2>err &&
34 grep "removing 3 leading" err
35'
36
bb7306b5
JN
37test_expect_success 'apply (-p2) traditional diff with funny filenames' '
38 cat >patch.quotes <<-\EOF &&
39 diff -u "a/"sub/file1 "b/"sub/file1
40 --- "a/"sub/file1
41 +++ "b/"sub/file1
42 @@ -1 +1 @@
43 -A
44 +B
45 EOF
46 echo B >expected &&
47
48 cp file1.saved file1 &&
49 git apply -p2 patch.quotes &&
50 test_cmp expected file1
51'
52
53test_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
57'
58
aae1f6ac
JH
59test_expect_success 'apply (-p2) diff, mode change only' '
60 cat >patch.chmod <<-\EOF &&
61 diff --git a/sub/file1 b/sub/file1
62 old mode 100644
63 new mode 100755
64 EOF
65 chmod 644 file1 &&
66 git apply -p2 patch.chmod &&
67 test -x file1
68'
69
70test_expect_success 'apply (-p2) diff, rename' '
71 cat >patch.rename <<-\EOF &&
72 diff --git a/sub/file1 b/sub/file2
73 similarity index 100%
74 rename from sub/file1
75 rename to sub/file2
76 EOF
77 echo A >expected &&
78
79 cp file1.saved file1 &&
80 rm -f file2 &&
81 git apply -p2 patch.rename &&
82 test_cmp expected file2
83'
84
79ee194e 85test_done