When no patches are applied, delete -n previously removed the first patch. Adds tests for quilt delete with and without -n when no patches are applied, top most and other applied patches. When pop fails during a delete, it will still remove the entry from applied-patches, and the state of the backup directory in .pc/ is unknown. AFAICS a strong warning is necessary. Index: quilt/quilt/delete.in =================================================================== --- quilt.orig/quilt/delete.in 2006-01-21 19:51:42.000000000 +1100 +++ quilt/quilt/delete.in 2006-01-21 19:52:38.000000000 +1100 @@ -77,22 +77,26 @@ usage fi -patch=$(find_patch_in_series "$1") || exit 1 - if [ -n "$opt_next" ] then - if ! patch="$(patch_after "$patch")" + if has_applied + then + patch=$(patch_after $(top_patch)) + elif ! patch=$(find_first_patch) then printf $"No next patch\n" >&2 exit 1 fi -elif is_applied "$patch" -then - if [ "$patch" != "$(top_patch)" ] || \ - ! quilt_command pop -fq - then - printf $"Patch %s is currently applied\n" \ - "$(print_patch $patch)" >&2 +elif [ -n "$1" -a "$1" != "$(top_patch)" ] +then + patch=$(find_unapplied_patch "$1") || exit 1 +else + patch=$(find_top_patch) || exit 1 + + if ! quilt_command pop -fq + then + printf $"Removing patch %s failed\n" \ + "$(print_patch "$patch")" >&2 exit 1 fi fi Index: quilt/quilt/scripts/patchfns.in =================================================================== --- quilt.orig/quilt/scripts/patchfns.in 2006-01-21 19:51:42.000000000 +1100 +++ quilt/quilt/scripts/patchfns.in 2006-01-21 19:52:38.000000000 +1100 @@ -330,6 +330,12 @@ grep -q "^$(quote_bre $patch)\$" $DB } +has_applied() +{ + [ -e $DB ] || return 1 + first=$(head -1 $DB) || return 1 +} + applied_patches() { [ -e $DB ] || return 1 @@ -536,7 +542,7 @@ patch=$(find_patch "$name") || return 1 if is_applied "$patch" then - printf $"Patch %s is already applied\n" \ + printf $"Patch %s is currently applied\n" \ "$(print_patch $patch)" >&2 return 1 fi Index: quilt/test/three.test =================================================================== --- quilt.orig/test/three.test 2006-01-21 19:51:43.000000000 +1100 +++ quilt/test/three.test 2006-01-21 19:52:38.000000000 +1100 @@ -135,7 +135,7 @@ > Now at patch patches/patch2.diff $ quilt push patch2 - > Patch patches/patch2.diff is already applied + > Patch patches/patch2.diff is currently applied $ quilt push > File series fully applied, ends at patch patches/patch2.diff Index: quilt/test/delete.test =================================================================== --- quilt.orig/test/delete.test 2006-01-21 19:52:25.000000000 +1100 +++ quilt/test/delete.test 2006-01-21 19:54:30.000000000 +1100 @@ -66,10 +66,9 @@ $ echo "test1" > %{P}series $ quilt delete -n - > No patches applied + > Removed patch %{P}test1 $ quilt series - > %{P}test1 # Force the pop operaton to fail $ echo "test3" > %{P}/series @@ -81,7 +80,7 @@ $ quilt delete "test3" > Removing patch %{P}test3 > .pc/test3/dir: Permission denied - > Patch %{P}test3 is currently applied + > Removing patch %{P}test3 failed $ chmod a+rx .pc/test3/dir