quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH 3/3] edit: Fix a corner case


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 3/3] edit: Fix a corner case
Date: Wed, 11 Feb 2015 09:09:58 +0100

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.
---
 quilt/edit.in  |    4 +++-
 test/edit.test |   33 ++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 2 deletions(-)

--- quilt.orig/quilt/edit.in    2015-02-11 08:59:52.451701044 +0100
+++ quilt/quilt/edit.in 2015-02-11 09:00:01.164922060 +0100
@@ -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
--- quilt.orig/test/edit.test   2015-02-11 08:59:52.451701044 +0100
+++ quilt/test/edit.test        2015-02-11 09:00:14.569260724 +0100
@@ -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

-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]