3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='add -e basic tests'
8 TEST_PASSES_SANITIZE_LEAK
=true
13 LO, praise of the prowess of people-kings
14 of spear-armed Danes, in days long sped,
15 we have heard, and what honor the athelings won!
16 Oft Scyld the Scefing from squadroned foes,
17 from many a tribe, the mead-bench tore,
18 awing the earls. Since erst he lay
19 friendless, a foundling, fate repaid him:
20 for he waxed under welkin, in wealth he throve,
21 till before him the folk, both far and near,
22 who house by the whale-path, heard his mandate,
23 gave him gifts: a good king he!
26 cat > second-part
<< EOF
27 To him an heir was afterward born,
28 a son in his halls, whom heaven sent
29 to favor the folk, feeling their woe
30 that erst they had lacked an earl for leader
31 so long a while; the Lord endowed him,
32 the Wielder of Wonder, with world's renown.
35 test_expect_success
'setup' '
39 git commit -m initial file
43 cat > expected-patch
<< EOF
44 diff --git a/file b/file
48 -LO, praise of the prowess of people-kings
49 -of spear-armed Danes, in days long sped,
50 -we have heard, and what honor the athelings won!
51 -Oft Scyld the Scefing from squadroned foes,
52 -from many a tribe, the mead-bench tore,
53 -awing the earls. Since erst he lay
54 -friendless, a foundling, fate repaid him:
55 -for he waxed under welkin, in wealth he throve,
56 -till before him the folk, both far and near,
57 -who house by the whale-path, heard his mandate,
58 -gave him gifts: a good king he!
59 +To him an heir was afterward born,
60 +a son in his halls, whom heaven sent
61 +to favor the folk, feeling their woe
62 +that erst they had lacked an earl for leader
63 +so long a while; the Lord endowed him,
64 +the Wielder of Wonder, with world's renown.
68 diff --git a/file b/file
69 index b9834b5..ef6e94c 100644
72 @@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped,
73 we have heard, and what honor the athelings won!
75 Oft Scyld the Scefing from squadroned foes,
76 @@ -2,7 +1,5 @@ awing the earls. Since erst he lay
77 friendless, a foundling, fate repaid him:
79 for he waxed under welkin, in wealth he throve,
83 diff --git a/file b/file
87 LO, praise of the prowess of people-kings
88 of spear-armed Danes, in days long sped,
89 we have heard, and what honor the athelings won!
91 Oft Scyld the Scefing from squadroned foes,
92 from many a tribe, the mead-bench tore,
93 awing the earls. Since erst he lay
94 friendless, a foundling, fate repaid him:
96 for he waxed under welkin, in wealth he throve,
97 till before him the folk, both far and near,
98 who house by the whale-path, heard his mandate,
101 echo "#!$SHELL_PATH" >fake-editor.sh
102 cat >> fake-editor.sh
<<\EOF
103 grep -E -v '^index' "$1" >orig-patch
&&
107 test_set_editor
"$(pwd)/fake-editor.sh"
108 chmod a
+x fake-editor.sh
110 test_expect_success
'add -e' '
112 cp second-part file &&
114 test_cmp second-part file &&
115 test_cmp expected-patch orig-patch &&
116 git diff --cached >actual &&
117 grep -v index actual >out &&
118 test_cmp expected out
122 test_expect_success
'add -e notices editor failure' '
124 echo change >>file &&
125 test_must_fail env GIT_EDITOR=false git add -e &&
126 test_expect_code 1 git diff --exit-code