git-add: introduce --edit (to edit the diff vs. the index)
[git/spearce.git] / t / t3702-add-edit.sh
blob72627863e5a9d00c758bcf96820a89827d310ba7
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 test_expect_success 'setup' '
26 git add file &&
27 test_tick &&
28 git commit -m initial file
32 cat > expected-patch << EOF
33 diff --git a/file b/file
34 index b9834b5..0b8f197 100644
35 --- a/file
36 +++ b/file
37 @@ -1,11 +1,3 @@
38 -LO, praise of the prowess of people-kings
39 -of spear-armed Danes, in days long sped,
40 -we have heard, and what honor the athelings won!
41 -Oft Scyld the Scefing from squadroned foes,
42 -from many a tribe, the mead-bench tore,
43 -awing the earls. Since erst he lay
44 -friendless, a foundling, fate repaid him:
45 -for he waxed under welkin, in wealth he throve,
46 -till before him the folk, both far and near,
47 -who house by the whale-path, heard his mandate,
48 -gave him gifts: a good king he!
49 +#!$SHELL_PATH
50 +mv -f "\$1" orig-patch &&
51 +mv -f patch "\$1"
52 EOF
54 cat > patch << EOF
55 diff --git a/file b/file
56 index b9834b5..ef6e94c 100644
57 --- a/file
58 +++ b/file
59 @@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped,
60 we have heard, and what honor the athelings won!
62 Oft Scyld the Scefing from squadroned foes,
63 @@ -2,7 +1,5 @@ awing the earls. Since erst he lay
64 friendless, a foundling, fate repaid him:
66 for he waxed under welkin, in wealth he throve,
67 EOF
69 cat > expected << EOF
70 diff --git a/file b/file
71 index b9834b5..ef6e94c 100644
72 --- a/file
73 +++ b/file
74 @@ -1,10 +1,12 @@
75 LO, praise of the prowess of people-kings
76 of spear-armed Danes, in days long sped,
77 we have heard, and what honor the athelings won!
79 Oft Scyld the Scefing from squadroned foes,
80 from many a tribe, the mead-bench tore,
81 awing the earls. Since erst he lay
82 friendless, a foundling, fate repaid him:
84 for he waxed under welkin, in wealth he throve,
85 till before him the folk, both far and near,
86 who house by the whale-path, heard his mandate,
87 EOF
89 echo "#!$SHELL_PATH" >fake-editor.sh
90 cat >> fake-editor.sh <<\EOF
91 mv -f "$1" orig-patch &&
92 mv -f patch "$1"
93 EOF
95 test_set_editor "$(pwd)/fake-editor.sh"
96 chmod a+x fake-editor.sh
98 test_expect_success 'add -e' '
100 cp fake-editor.sh file &&
101 git add -e &&
102 test_cmp fake-editor.sh file &&
103 test_cmp orig-patch expected-patch &&
104 git diff --cached > out &&
105 test_cmp out expected
109 test_done