Re: [PATCH 2/2] Allow deletion of several patches at once

Previous thread: [PATCH] RFC2047-encode email headers by Karl on Sunday, October 22, 2006 - 5:02 am. (5 messages)

Next thread: Re: VCS comparison table by Matthew D. Fuller on Sunday, October 22, 2006 - 6:03 am. (2 messages)
From: Karl
Date: Sunday, October 22, 2006 - 5:53 am

The first patch introduces a test for "stg delete", since there wasn't
already one, and it's much less stressful to modify stuff if you have
an automatic test that can tell you if you broke stuff.

As it turns out, this test finds an existing bug: it's not possible to
delete a patch in another branch if there's an identically named
branch in the current branch, and both patches are topmost in their
respective applied stacks.

The second patch teaches "delete" how to delete multiple patches in
one go.

--=20
Karl Hasselstr=C3=B6m, kha@treskal.com
      www.treskal.com/kalle
-

From: Karl
Date: Sunday, October 22, 2006 - 5:58 am

From: Karl Hasselstr=C3=B6m <kha@treskal.com>



Signed-off-by: Karl Hasselstr=C3=B6m <kha@treskal.com>
---

 stgit/commands/delete.py |   50 ++++++++++++++++-----
 t/t1600-delete-one.sh    |  109 ++++++++++++++++++++++++++++++++++++++++++=
++++
 t/t1600-delete.sh        |  109 ------------------------------------------=
----
 t/t1601-delete-many.sh   |   45 +++++++++++++++++++
 4 files changed, 193 insertions(+), 120 deletions(-)

diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py
index c97d8ed..5617ca1 100644
--- a/stgit/commands/delete.py
+++ b/stgit/commands/delete.py
@@ -24,13 +24,16 @@ from stgit.utils import *
 from stgit import stack, git
=20
=20
-help =3D 'remove the topmost or any unapplied patch'
-usage =3D """%prog [options] <patch>
+help =3D 'delete patches'
+usage =3D """%prog [options] <patch> [ <patch> [...] ]
=20
-Delete the patch passed as argument. The patch to be deleted can only
-be part of the unapplied list or be the topmost one, in the latter
-case the command also popping it from the stack. Note that the
-'delete' operation is irreversible."""
+Delete the patches passed as arguments. If an applied patch is to be
+deleted, all other patches applied on top of it must be deleted too;
+and they must be explicitly specified, since this command will not try
+to delete a patch unless you explicitly ask it to. If any applied
+patches are deleted, they are popped from the stack.
+
+Note that the 'delete' operation is irreversible."""
=20
 options =3D [make_option('-b', '--branch',
                        help =3D 'use BRANCH instead of the default one')]
@@ -38,16 +41,41 @@ options =3D [make_option('-b', '--branch',
 def func(parser, options, args):
     """Deletes a patch
     """
-    if len(args) !=3D 1:
-        parser.error('incorrect number of arguments')
+    if not args:
+        parser.error('no patches to delete')
+
+    applied =3D {}
+    unapplied =3D {}
+    dontexist =3D {}
+    for patch in args:
+        if ...
From: Karl
Date: Sunday, October 22, 2006 - 6:01 am

On 2006-10-22 14:58:16 +0200, Karl Hasselstr
From: Catalin Marinas
Date: Monday, October 23, 2006 - 4:57 am

On 22/10/06, Karl Hasselstr
From: Karl
Date: Monday, October 23, 2006 - 5:37 am

On 2006-10-23 12:57:03 +0100, Catalin Marinas wrote:

> On 22/10/06, Karl Hasselstr
From: Karl
Date: Wednesday, November 1, 2006 - 2:07 am

From: Karl Hasselstr=C3=B6m <kha@treskal.com>

Signed-off-by: Karl Hasselstr=C3=B6m <kha@treskal.com>
---

This is an updated patch, which uses parse_patches() to support patch
ranges. It replaces patch 2/2 in the series; patch 1/2 (original
delete regression test) is unaffected.

 stgit/commands/delete.py |   54 +++++++++++++++++------
 t/t1600-delete-one.sh    |  109 ++++++++++++++++++++++++++++++++++++++++++=
++++
 t/t1600-delete.sh        |  109 ------------------------------------------=
----
 t/t1601-delete-many.sh   |   55 +++++++++++++++++++++++
 4 files changed, 205 insertions(+), 122 deletions(-)

diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py
index c97d8ed..2f3aece 100644
--- a/stgit/commands/delete.py
+++ b/stgit/commands/delete.py
@@ -24,30 +24,58 @@ from stgit.utils import *
 from stgit import stack, git
=20
=20
-help =3D 'remove the topmost or any unapplied patch'
-usage =3D """%prog [options] <patch>
+help =3D 'delete patches'
+usage =3D """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
=20
-Delete the patch passed as argument. The patch to be deleted can only
-be part of the unapplied list or be the topmost one, in the latter
-case the command also popping it from the stack. Note that the
-'delete' operation is irreversible."""
+Delete the patches passed as arguments. If an applied patch is to be
+deleted, all other patches applied on top of it must be deleted too;
+and they must be explicitly specified, since this command will not try
+to delete a patch unless you explicitly ask it to. If any applied
+patches are deleted, they are popped from the stack.
+
+Note that the 'delete' operation is irreversible."""
=20
 options =3D [make_option('-b', '--branch',
                        help =3D 'use BRANCH instead of the default one')]
=20
 def func(parser, options, args):
-    """Deletes a patch
-    """
-    if len(args) !=3D 1:
-        parser.error('incorrect number of arguments')
+    """Deletes one or more ...
From: Catalin Marinas
Date: Thursday, November 2, 2006 - 3:36 am

On 01/11/06, Karl Hasselstr
From: Karl
Date: Sunday, October 22, 2006 - 5:58 am

From: Karl Hasselstr=C3=B6m <kha@treskal.com>

NOTE: The subtest that attempts to delete a patch in another branch
currently fails, because there's a bug in "delete".

Signed-off-by: Karl Hasselstr=C3=B6m <kha@treskal.com>
---

 t/t1600-delete.sh |  109 +++++++++++++++++++++++++++++++++++++++++++++++++=
++++
 1 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/t/t1600-delete.sh b/t/t1600-delete.sh
new file mode 100644
index 0000000..e22e624
--- /dev/null
+++ b/t/t1600-delete.sh
@@ -0,0 +1,109 @@
+#!/bin/sh
+# Copyright (c) 2006 Karl Hasselstr=C3=B6m
+test_description=3D'Test the delete command.'
+=2E ./test-lib.sh
+
+test_expect_success \
+    'Initialize the StGIT repository' \
+    'stg init'
+
+test_expect_success \
+    'Create a patch' \
+    '
+    stg new foo -m foo &&
+    echo foo > foo.txt &&
+    stg add foo.txt &&
+    stg refresh
+    '
+
+test_expect_success \
+    'Try to delete a non-existing patch' \
+    '
+    [ $(stg applied | wc -l) -eq 1 ] &&
+    ! stg delete bar &&
+    [ $(stg applied | wc -l) -eq 1 ]
+    '
+
+test_expect_success \
+    'Try to delete the topmost patch while dirty' \
+    '
+    echo dirty >> foo.txt &&
+    [ $(stg applied | wc -l) -eq 1 ] &&
+    ! stg delete foo &&
+    [ $(stg applied | wc -l) -eq 1 ] &&
+    git reset --hard
+    '
+
+test_expect_success \
+    'Delete the topmost patch' \
+    '
+    [ $(stg applied | wc -l) -eq 1 ] &&
+    stg delete foo &&
+    [ $(stg applied | wc -l) -eq 0 ]
+    '
+
+test_expect_success \
+    'Create an unapplied patch' \
+    '
+    stg new foo -m foo &&
+    echo foo > foo.txt &&
+    stg add foo.txt &&
+    stg refresh &&
+    stg pop
+    '
+
+test_expect_success \
+    'Delete an unapplied patch' \
+    '
+    [ $(stg unapplied | wc -l) -eq 1 ] &&
+    stg delete foo &&
+    [ $(stg unapplied | wc -l) -eq 0 ]
+    '
+
+test_expect_success \
+    'Create two patches' \
+    '
+    stg new foo -m foo &&
+    echo foo > ...
Previous thread: [PATCH] RFC2047-encode email headers by Karl on Sunday, October 22, 2006 - 5:02 am. (5 messages)

Next thread: Re: VCS comparison table by Matthew D. Fuller on Sunday, October 22, 2006 - 6:03 am. (2 messages)