git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Johannes E. Schindelin
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='add -e basic tests'
|
2021-10-31 00:24:20 +02:00
|
|
|
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
|
|
|
|
cat > file << EOF
|
|
|
|
LO, praise of the prowess of people-kings
|
|
|
|
of spear-armed Danes, in days long sped,
|
|
|
|
we have heard, and what honor the athelings won!
|
|
|
|
Oft Scyld the Scefing from squadroned foes,
|
|
|
|
from many a tribe, the mead-bench tore,
|
|
|
|
awing the earls. Since erst he lay
|
|
|
|
friendless, a foundling, fate repaid him:
|
|
|
|
for he waxed under welkin, in wealth he throve,
|
|
|
|
till before him the folk, both far and near,
|
|
|
|
who house by the whale-path, heard his mandate,
|
|
|
|
gave him gifts: a good king he!
|
|
|
|
EOF
|
|
|
|
|
2009-04-27 19:51:42 +02:00
|
|
|
cat > second-part << EOF
|
|
|
|
To him an heir was afterward born,
|
|
|
|
a son in his halls, whom heaven sent
|
|
|
|
to favor the folk, feeling their woe
|
|
|
|
that erst they had lacked an earl for leader
|
|
|
|
so long a while; the Lord endowed him,
|
|
|
|
the Wielder of Wonder, with world's renown.
|
|
|
|
EOF
|
|
|
|
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m initial file
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
cat > expected-patch << EOF
|
|
|
|
diff --git a/file b/file
|
|
|
|
--- a/file
|
|
|
|
+++ b/file
|
2009-04-27 19:51:42 +02:00
|
|
|
@@ -1,11 +1,6 @@
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
-LO, praise of the prowess of people-kings
|
|
|
|
-of spear-armed Danes, in days long sped,
|
|
|
|
-we have heard, and what honor the athelings won!
|
|
|
|
-Oft Scyld the Scefing from squadroned foes,
|
|
|
|
-from many a tribe, the mead-bench tore,
|
|
|
|
-awing the earls. Since erst he lay
|
|
|
|
-friendless, a foundling, fate repaid him:
|
|
|
|
-for he waxed under welkin, in wealth he throve,
|
|
|
|
-till before him the folk, both far and near,
|
|
|
|
-who house by the whale-path, heard his mandate,
|
|
|
|
-gave him gifts: a good king he!
|
2009-04-27 19:51:42 +02:00
|
|
|
+To him an heir was afterward born,
|
|
|
|
+a son in his halls, whom heaven sent
|
|
|
|
+to favor the folk, feeling their woe
|
|
|
|
+that erst they had lacked an earl for leader
|
|
|
|
+so long a while; the Lord endowed him,
|
|
|
|
+the Wielder of Wonder, with world's renown.
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > patch << EOF
|
|
|
|
diff --git a/file b/file
|
|
|
|
index b9834b5..ef6e94c 100644
|
|
|
|
--- a/file
|
|
|
|
+++ b/file
|
|
|
|
@@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped,
|
|
|
|
we have heard, and what honor the athelings won!
|
|
|
|
+
|
|
|
|
Oft Scyld the Scefing from squadroned foes,
|
|
|
|
@@ -2,7 +1,5 @@ awing the earls. Since erst he lay
|
|
|
|
friendless, a foundling, fate repaid him:
|
|
|
|
+
|
|
|
|
for he waxed under welkin, in wealth he throve,
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > expected << EOF
|
|
|
|
diff --git a/file b/file
|
|
|
|
--- a/file
|
|
|
|
+++ b/file
|
|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
LO, praise of the prowess of people-kings
|
|
|
|
of spear-armed Danes, in days long sped,
|
|
|
|
we have heard, and what honor the athelings won!
|
|
|
|
+
|
|
|
|
Oft Scyld the Scefing from squadroned foes,
|
|
|
|
from many a tribe, the mead-bench tore,
|
|
|
|
awing the earls. Since erst he lay
|
|
|
|
friendless, a foundling, fate repaid him:
|
|
|
|
+
|
|
|
|
for he waxed under welkin, in wealth he throve,
|
|
|
|
till before him the folk, both far and near,
|
|
|
|
who house by the whale-path, heard his mandate,
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "#!$SHELL_PATH" >fake-editor.sh
|
|
|
|
cat >> fake-editor.sh <<\EOF
|
2022-09-21 15:02:31 +02:00
|
|
|
grep -E -v '^index' "$1" >orig-patch &&
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
mv -f patch "$1"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_set_editor "$(pwd)/fake-editor.sh"
|
|
|
|
chmod a+x fake-editor.sh
|
|
|
|
|
|
|
|
test_expect_success 'add -e' '
|
|
|
|
|
2009-04-27 19:51:42 +02:00
|
|
|
cp second-part file &&
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
git add -e &&
|
2009-04-27 19:51:42 +02:00
|
|
|
test_cmp second-part file &&
|
2018-10-05 23:54:04 +02:00
|
|
|
test_cmp expected-patch orig-patch &&
|
2018-05-21 04:01:32 +02:00
|
|
|
git diff --cached >actual &&
|
|
|
|
grep -v index actual >out &&
|
2018-10-05 23:54:04 +02:00
|
|
|
test_cmp expected out
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2015-05-13 03:21:58 +02:00
|
|
|
test_expect_success 'add -e notices editor failure' '
|
|
|
|
git reset --hard &&
|
|
|
|
echo change >>file &&
|
|
|
|
test_must_fail env GIT_EDITOR=false git add -e &&
|
|
|
|
test_expect_code 1 git diff --exit-code
|
|
|
|
'
|
|
|
|
|
git-add: introduce --edit (to edit the diff vs. the index)
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the hunks
if necessary, thanks to the --recount option of apply, and commit the
patch. Except if you deleted everything, in which case nothing happens
(for obvious reasons).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08 23:30:24 +02:00
|
|
|
test_done
|