summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2015-02-18 13:00:05 +0100
committerJean Delvare <jdelvare@suse.de>2015-02-18 13:00:05 +0100
commit86a58469ae2d2d60d84cb6fb487d2c946158ef67 (patch)
treea2c664d99ae26973cba3c97fe9b762c5dfb145a1
parent90459af8fa29670f0e3359c291aec46e34db9ce2 (diff)
downloadquilt-86a58469ae2d2d60d84cb6fb487d2c946158ef67.tar.gz
edit: Fix a corner case
There is one corner case which is not properly handled by the "edit" command. If a patch deletes a file, and the user calls "quilt edit" on that file but does not actually add anything back to it, "quilt remove" is called on the file when the editor exits. This causes the file to be restored to its original state before the patch deleted it. The user never asked for that, so the file should be left to its deleted state in this case. The file must only be removed from the patch if it was not part of the patch originally. The same problem would occur if the editor deleted the file. In general text editors don't do that, they'd leave an empty file instead, but nothing prevents them from actually deleting the file so we should handle this case properly too.
-rw-r--r--quilt/edit.in4
-rw-r--r--test/edit.test33
2 files changed, 35 insertions, 2 deletions
diff --git a/quilt/edit.in b/quilt/edit.in
index b9a84dd..cb84fd9 100644
--- a/quilt/edit.in
+++ b/quilt/edit.in
@@ -67,9 +67,11 @@ then
fi
LANG=$ORIGINAL_LANG $EDITOR "${@/#/$SUBDIR}"
status=$?
+
+patch=$(top_patch)
for file in "$@"
do
- if ! [ -e "$SUBDIR$file" ]
+ if [ ! -e "$SUBDIR$file" -a ! -s "$QUILT_PC/$patch/$file" ]
then
quilt_command remove "$file"
status=1
diff --git a/test/edit.test b/test/edit.test
index daa30be..2091305 100644
--- a/test/edit.test
+++ b/test/edit.test
@@ -37,6 +37,19 @@ $ quilt files
$ quilt refresh
> Refreshed patch patches/patch
+# Test the behavior if the editor deletes a file completely
+$ echo foobaz > foobaz
+$ cat > editor
+< #! /bin/sh
+< echo Deleting $1
+< rm -f $1
+
+$ quilt edit foobaz
+> File foobaz added to patch patches/patch
+> Deleting foobaz
+
+$ [ ! -e foobaz ] || echo "File foobaz shouldn't exist"
+
# Test the behavior if the editor is called on a new file but
# does not actually create it
$ cat > editor
@@ -48,6 +61,23 @@ $ quilt edit nofoo
> Doing nothing to nofoo
> File nofoo removed from patch patches/patch
+# Test the behavior if the patch is deleting a file and the
+# user calls "quilt edit" on that file but makes no change to it
+$ rm -f foobar
+$ quilt refresh
+> Refreshed patch patches/patch
+$ quilt diff -p ab --no-index foobar
+> --- a/foobar
+> +++ /dev/null
+> @@ -1 +0,0 @@
+> -foobar
+
+$ quilt edit foobar
+> File foobar is already in patch patches/patch
+> Doing nothing to foobar
+
+$ [ ! -e foobar ] || echo "File foobar shouldn't exist"
+
# Test the behavior if the editor creates a brand new file
$ cat > editor
< #! /bin/sh
@@ -62,5 +92,6 @@ $ cat foo2
$ quilt files -v
> + foo2
-> foobar
+> - foobar
+> - foobaz
> subdir/foo