Merge branch 'pc/submodule-helper-foreach'
[git/raj.git] / t / t3702-add-edit.sh
blobc6af7f82b58f606b3f6c7e2612931a1fc2af15c7
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='add -e basic tests'
7 . ./test-lib.sh
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
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
33 test_expect_success 'setup' '
35 git add file &&
36 test_tick &&
37 git commit -m initial file
41 cat > expected-patch << EOF
42 diff --git a/file b/file
43 --- a/file
44 +++ b/file
45 @@ -1,11 +1,6 @@
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.
63 EOF
65 cat > patch << EOF
66 diff --git a/file b/file
67 index b9834b5..ef6e94c 100644
68 --- a/file
69 +++ b/file
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,
78 EOF
80 cat > expected << EOF
81 diff --git a/file b/file
82 --- a/file
83 +++ b/file
84 @@ -1,10 +1,12 @@
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,
97 EOF
99 echo "#!$SHELL_PATH" >fake-editor.sh
100 cat >> fake-editor.sh <<\EOF
101 egrep -v '^index' "$1" >orig-patch &&
102 mv -f patch "$1"
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 &&
111 git add -e &&
112 test_cmp second-part file &&
113 test_cmp orig-patch expected-patch &&
114 git diff --cached >actual &&
115 grep -v index actual >out &&
116 test_cmp out expected
120 test_expect_success 'add -e notices editor failure' '
121 git reset --hard &&
122 echo change >>file &&
123 test_must_fail env GIT_EDITOR=false git add -e &&
124 test_expect_code 1 git diff --exit-code
127 test_done