]>
Commit | Line | Data |
---|---|---|
18bc7616 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='add -i basic tests' | |
4 | . ./test-lib.sh | |
5 | ||
6 | test_expect_success 'setup (initial)' ' | |
7 | echo content >file && | |
8 | git add file && | |
9 | echo more >>file && | |
10 | echo lines >>file | |
11 | ' | |
12 | test_expect_success 'status works (initial)' ' | |
13 | git add -i </dev/null >output && | |
14 | grep "+1/-0 *+2/-0 file" output | |
15 | ' | |
16 | cat >expected <<EOF | |
17 | new file mode 100644 | |
18 | index 0000000..d95f3ad | |
19 | --- /dev/null | |
20 | +++ b/file | |
21 | @@ -0,0 +1 @@ | |
22 | +content | |
23 | EOF | |
24 | test_expect_success 'diff works (initial)' ' | |
25 | (echo d; echo 1) | git add -i >output && | |
26 | sed -ne "/new file/,/content/p" <output >diff && | |
82ebb0b6 | 27 | test_cmp expected diff |
18bc7616 JK |
28 | ' |
29 | test_expect_success 'revert works (initial)' ' | |
30 | git add file && | |
31 | (echo r; echo 1) | git add -i && | |
32 | git ls-files >output && | |
33 | ! grep . output | |
34 | ' | |
35 | ||
36 | test_expect_success 'setup (commit)' ' | |
37 | echo baseline >file && | |
38 | git add file && | |
39 | git commit -m commit && | |
40 | echo content >>file && | |
41 | git add file && | |
42 | echo more >>file && | |
43 | echo lines >>file | |
44 | ' | |
45 | test_expect_success 'status works (commit)' ' | |
46 | git add -i </dev/null >output && | |
47 | grep "+1/-0 *+2/-0 file" output | |
48 | ' | |
49 | cat >expected <<EOF | |
50 | index 180b47c..b6f2c08 100644 | |
51 | --- a/file | |
52 | +++ b/file | |
53 | @@ -1 +1,2 @@ | |
54 | baseline | |
55 | +content | |
56 | EOF | |
57 | test_expect_success 'diff works (commit)' ' | |
58 | (echo d; echo 1) | git add -i >output && | |
59 | sed -ne "/^index/,/content/p" <output >diff && | |
82ebb0b6 | 60 | test_cmp expected diff |
18bc7616 JK |
61 | ' |
62 | test_expect_success 'revert works (commit)' ' | |
63 | git add file && | |
64 | (echo r; echo 1) | git add -i && | |
65 | git add -i </dev/null >output && | |
66 | grep "unchanged *+3/-0 file" output | |
67 | ' | |
68 | ||
b717a627 JK |
69 | test_expect_success 'patch does not affect mode' ' |
70 | git reset --hard && | |
71 | echo content >>file && | |
72 | chmod +x file && | |
ca724686 | 73 | printf "n\\ny\\n" | git add -p && |
b717a627 JK |
74 | git show :file | grep content && |
75 | git diff file | grep "new mode" | |
76 | ' | |
77 | ||
ca724686 JK |
78 | test_expect_success 'stage mode but not hunk' ' |
79 | git reset --hard && | |
80 | echo content >>file && | |
81 | chmod +x file && | |
82 | printf "y\\nn\\n" | git add -p && | |
83 | git diff --cached file | grep "new mode" && | |
84 | git diff file | grep "+content" | |
85 | ' | |
86 | ||
87 | ||
18bc7616 | 88 | test_done |