1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn O. Pearce
4#
56
test_description='git apply -p handling.'
78
. ./test-lib.sh
910
test_expect_success setup '
11mkdir sub &&
12echo A >sub/file1 &&
13cp sub/file1 file1.saved &&
14git add sub/file1 &&
15echo B >sub/file1 &&
16git diff >patch.file &&
17git checkout -- sub/file1 &&
18git mv sub süb &&
19echo B >süb/file1 &&
20git diff >patch.escaped &&
21grep "[\]" patch.escaped &&
22rm süb/file1 &&
23rmdir süb
24'
2526
test_expect_success 'apply git diff with -p2' '
27cp file1.saved file1 &&
28git apply -p2 patch.file
29'
3031
test_expect_success 'apply with too large -p' '
32cp file1.saved file1 &&
33test_must_fail git apply --stat -p3 patch.file 2>err &&
34grep "removing 3 leading" err
35'
3637
test_expect_success 'apply (-p2) traditional diff with funny filenames' '
38cat >patch.quotes <<-\EOF &&
39diff -u "a/"sub/file1 "b/"sub/file1
40--- "a/"sub/file1
41+++ "b/"sub/file1
42@@ -1 +1 @@
43-A
44+B
45EOF
46echo B >expected &&
4748
cp file1.saved file1 &&
49git apply -p2 patch.quotes &&
50test_cmp expected file1
51'
5253
test_expect_success 'apply with too large -p and fancy filename' '
54cp file1.saved file1 &&
55test_must_fail git apply --stat -p3 patch.escaped 2>err &&
56grep "removing 3 leading" err
57'
5859
test_expect_success 'apply (-p2) diff, mode change only' '
60cat >patch.chmod <<-\EOF &&
61diff --git a/sub/file1 b/sub/file1
62old mode 100644
63new mode 100755
64EOF
65chmod 644 file1 &&
66git apply -p2 patch.chmod &&
67test -x file1
68'
6970
test_expect_success 'apply (-p2) diff, rename' '
71cat >patch.rename <<-\EOF &&
72diff --git a/sub/file1 b/sub/file2
73similarity index 100%
74rename from sub/file1
75rename to sub/file2
76EOF
77echo A >expected &&
7879
cp file1.saved file1 &&
80rm -f file2 &&
81git apply -p2 patch.rename &&
82test_cmp expected file2
83'
8485
test_done