3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='add -e basic tests'
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!
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.
33 test_expect_success 'setup' '
37 git commit -m initial file
41 cat > expected-patch << EOF
42 diff --git a/file b/file
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!
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.
66 diff --git a/file b/file
67 index b9834b5..ef6e94c 100644
70 @@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped,
71 we have heard, and what honor the athelings won!
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:
77 for he waxed under welkin, in wealth he throve,
81 diff --git a/file b/file
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!
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:
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,
99 echo "#!$SHELL_PATH" >fake-editor.sh
100 cat >> fake-editor.sh <<\EOF
101 egrep -v '^index' "$1" >orig-patch &&
105 test_set_editor "$(pwd)/fake-editor.sh"
106 chmod a+x fake-editor.sh
108 test_expect_success 'add -e' '
110 cp second-part file &&
112 test_cmp second-part file &&
113 test_cmp expected-patch orig-patch &&
114 git diff --cached >actual &&
115 grep -v index actual >out &&
116 test_cmp expected out
120 test_expect_success 'add -e notices editor failure' '
122 echo change >>file &&
123 test_must_fail env GIT_EDITOR=false git add -e &&
124 test_expect_code 1 git diff --exit-code