2.36 fast-export regression fix
[git.git] / t / t3702-add-edit.sh
bloba1801a8cbd4185f80253b019eb40a2c6a378d7ab
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='add -e basic tests'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
12 cat > file << EOF
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!
24 EOF
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.
33 EOF
35 test_expect_success 'setup' '
37 git add file &&
38 test_tick &&
39 git commit -m initial file
43 cat > expected-patch << EOF
44 diff --git a/file b/file
45 --- a/file
46 +++ b/file
47 @@ -1,11 +1,6 @@
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.
65 EOF
67 cat > patch << EOF
68 diff --git a/file b/file
69 index b9834b5..ef6e94c 100644
70 --- a/file
71 +++ b/file
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,
80 EOF
82 cat > expected << EOF
83 diff --git a/file b/file
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!
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,
99 EOF
101 echo "#!$SHELL_PATH" >fake-editor.sh
102 cat >> fake-editor.sh <<\EOF
103 egrep -v '^index' "$1" >orig-patch &&
104 mv -f patch "$1"
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 &&
113 git add -e &&
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' '
123 git reset --hard &&
124 echo change >>file &&
125 test_must_fail env GIT_EDITOR=false git add -e &&
126 test_expect_code 1 git diff --exit-code
129 test_done