]>
Commit | Line | Data |
---|---|---|
c59cb03a JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Johannes E. Schindelin | |
4 | # | |
5 | ||
6 | test_description='add -e basic tests' | |
7 | . ./test-lib.sh | |
8 | ||
9 | ||
10 | cat > file << EOF | |
11 | LO, praise of the prowess of people-kings | |
12 | of spear-armed Danes, in days long sped, | |
13 | we have heard, and what honor the athelings won! | |
14 | Oft Scyld the Scefing from squadroned foes, | |
15 | from many a tribe, the mead-bench tore, | |
16 | awing the earls. Since erst he lay | |
17 | friendless, a foundling, fate repaid him: | |
18 | for he waxed under welkin, in wealth he throve, | |
19 | till before him the folk, both far and near, | |
20 | who house by the whale-path, heard his mandate, | |
21 | gave him gifts: a good king he! | |
22 | EOF | |
23 | ||
7c8224b6 JS |
24 | cat > second-part << EOF |
25 | To him an heir was afterward born, | |
26 | a son in his halls, whom heaven sent | |
27 | to favor the folk, feeling their woe | |
28 | that erst they had lacked an earl for leader | |
29 | so long a while; the Lord endowed him, | |
30 | the Wielder of Wonder, with world's renown. | |
31 | EOF | |
32 | ||
c59cb03a JS |
33 | test_expect_success 'setup' ' |
34 | ||
35 | git add file && | |
36 | test_tick && | |
37 | git commit -m initial file | |
38 | ||
39 | ' | |
40 | ||
41 | cat > expected-patch << EOF | |
42 | diff --git a/file b/file | |
c59cb03a JS |
43 | --- a/file |
44 | +++ b/file | |
7c8224b6 | 45 | @@ -1,11 +1,6 @@ |
c59cb03a JS |
46 | -LO, praise of the prowess of people-kings |
47 | -of spear-armed Danes, in days long sped, | |
48 | -we have heard, and what honor the athelings won! | |
49 | -Oft Scyld the Scefing from squadroned foes, | |
50 | -from many a tribe, the mead-bench tore, | |
51 | -awing the earls. Since erst he lay | |
52 | -friendless, a foundling, fate repaid him: | |
53 | -for he waxed under welkin, in wealth he throve, | |
54 | -till before him the folk, both far and near, | |
55 | -who house by the whale-path, heard his mandate, | |
56 | -gave him gifts: a good king he! | |
7c8224b6 JS |
57 | +To him an heir was afterward born, |
58 | +a son in his halls, whom heaven sent | |
59 | +to favor the folk, feeling their woe | |
60 | +that erst they had lacked an earl for leader | |
61 | +so long a while; the Lord endowed him, | |
62 | +the Wielder of Wonder, with world's renown. | |
c59cb03a JS |
63 | EOF |
64 | ||
65 | cat > patch << EOF | |
66 | diff --git a/file b/file | |
67 | index b9834b5..ef6e94c 100644 | |
68 | --- a/file | |
69 | +++ b/file | |
70 | @@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped, | |
71 | we have heard, and what honor the athelings won! | |
72 | + | |
73 | Oft Scyld the Scefing from squadroned foes, | |
74 | @@ -2,7 +1,5 @@ awing the earls. Since erst he lay | |
75 | friendless, a foundling, fate repaid him: | |
76 | + | |
77 | for he waxed under welkin, in wealth he throve, | |
78 | EOF | |
79 | ||
80 | cat > expected << EOF | |
81 | diff --git a/file b/file | |
c59cb03a JS |
82 | --- a/file |
83 | +++ b/file | |
84 | @@ -1,10 +1,12 @@ | |
85 | LO, praise of the prowess of people-kings | |
86 | of spear-armed Danes, in days long sped, | |
87 | we have heard, and what honor the athelings won! | |
88 | + | |
89 | Oft Scyld the Scefing from squadroned foes, | |
90 | from many a tribe, the mead-bench tore, | |
91 | awing the earls. Since erst he lay | |
92 | friendless, a foundling, fate repaid him: | |
93 | + | |
94 | for he waxed under welkin, in wealth he throve, | |
95 | till before him the folk, both far and near, | |
96 | who house by the whale-path, heard his mandate, | |
97 | EOF | |
98 | ||
99 | echo "#!$SHELL_PATH" >fake-editor.sh | |
100 | cat >> fake-editor.sh <<\EOF | |
18cb8231 | 101 | egrep -v '^index' "$1" >orig-patch && |
c59cb03a JS |
102 | mv -f patch "$1" |
103 | EOF | |
104 | ||
105 | test_set_editor "$(pwd)/fake-editor.sh" | |
106 | chmod a+x fake-editor.sh | |
107 | ||
108 | test_expect_success 'add -e' ' | |
109 | ||
7c8224b6 | 110 | cp second-part file && |
c59cb03a | 111 | git add -e && |
7c8224b6 | 112 | test_cmp second-part file && |
dcbaa0b3 | 113 | test_cmp expected-patch orig-patch && |
18cb8231 | 114 | git diff --cached >actual && |
115 | grep -v index actual >out && | |
dcbaa0b3 | 116 | test_cmp expected out |
c59cb03a JS |
117 | |
118 | ' | |
119 | ||
cb64800d JK |
120 | test_expect_success 'add -e notices editor failure' ' |
121 | git reset --hard && | |
122 | echo change >>file && | |
123 | test_must_fail env GIT_EDITOR=false git add -e && | |
124 | test_expect_code 1 git diff --exit-code | |
125 | ' | |
126 | ||
c59cb03a | 127 | test_done |