]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3702-add-edit.sh
The third batch
[thirdparty/git.git] / t / t3702-add-edit.sh
CommitLineData
c59cb03a
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='add -e basic tests'
aecb85bd
ÆAB
7
8TEST_PASSES_SANITIZE_LEAK=true
c59cb03a
JS
9. ./test-lib.sh
10
11
12cat > file << EOF
13LO, praise of the prowess of people-kings
14of spear-armed Danes, in days long sped,
15we have heard, and what honor the athelings won!
16Oft Scyld the Scefing from squadroned foes,
17from many a tribe, the mead-bench tore,
18awing the earls. Since erst he lay
19friendless, a foundling, fate repaid him:
20for he waxed under welkin, in wealth he throve,
21till before him the folk, both far and near,
22who house by the whale-path, heard his mandate,
23gave him gifts: a good king he!
24EOF
25
7c8224b6
JS
26cat > second-part << EOF
27To him an heir was afterward born,
28a son in his halls, whom heaven sent
29to favor the folk, feeling their woe
30that erst they had lacked an earl for leader
31so long a while; the Lord endowed him,
32the Wielder of Wonder, with world's renown.
33EOF
34
c59cb03a
JS
35test_expect_success 'setup' '
36
37 git add file &&
38 test_tick &&
39 git commit -m initial file
40
41'
42
43cat > expected-patch << EOF
44diff --git a/file b/file
c59cb03a
JS
45--- a/file
46+++ b/file
7c8224b6 47@@ -1,11 +1,6 @@
c59cb03a
JS
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!
7c8224b6
JS
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.
c59cb03a
JS
65EOF
66
67cat > patch << EOF
68diff --git a/file b/file
69index 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!
74+
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:
78+
79 for he waxed under welkin, in wealth he throve,
80EOF
81
82cat > expected << EOF
83diff --git a/file b/file
c59cb03a
JS
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,
99EOF
100
101echo "#!$SHELL_PATH" >fake-editor.sh
102cat >> fake-editor.sh <<\EOF
81580fa0 103grep -E -v '^index' "$1" >orig-patch &&
c59cb03a
JS
104mv -f patch "$1"
105EOF
106
107test_set_editor "$(pwd)/fake-editor.sh"
108chmod a+x fake-editor.sh
109
110test_expect_success 'add -e' '
111
7c8224b6 112 cp second-part file &&
c59cb03a 113 git add -e &&
7c8224b6 114 test_cmp second-part file &&
dcbaa0b3 115 test_cmp expected-patch orig-patch &&
18cb8231 116 git diff --cached >actual &&
117 grep -v index actual >out &&
dcbaa0b3 118 test_cmp expected out
c59cb03a
JS
119
120'
121
cb64800d
JK
122test_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
127'
128
c59cb03a 129test_done