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