]>
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 | |
7c8224b6 | 43 | index b9834b5..9020acb 100644 |
c59cb03a JS |
44 | --- a/file |
45 | +++ b/file | |
7c8224b6 | 46 | @@ -1,11 +1,6 @@ |
c59cb03a JS |
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! | |
7c8224b6 JS |
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. | |
c59cb03a JS |
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 | index b9834b5..ef6e94c 100644 | |
84 | --- a/file | |
85 | +++ b/file | |
86 | @@ -1,10 +1,12 @@ | |
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! | |
90 | + | |
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: | |
95 | + | |
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, | |
99 | EOF | |
100 | ||
101 | echo "#!$SHELL_PATH" >fake-editor.sh | |
102 | cat >> fake-editor.sh <<\EOF | |
103 | mv -f "$1" orig-patch && | |
104 | mv -f patch "$1" | |
105 | EOF | |
106 | ||
107 | test_set_editor "$(pwd)/fake-editor.sh" | |
108 | chmod a+x fake-editor.sh | |
109 | ||
110 | test_expect_success 'add -e' ' | |
111 | ||
7c8224b6 | 112 | cp second-part file && |
c59cb03a | 113 | git add -e && |
7c8224b6 | 114 | test_cmp second-part file && |
c59cb03a JS |
115 | test_cmp orig-patch expected-patch && |
116 | git diff --cached > out && | |
117 | test_cmp out expected | |
118 | ||
119 | ' | |
120 | ||
cb64800d JK |
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 | ||
c59cb03a | 128 | test_done |