threads / patch / 12160

patchAllow renaming of the top-most branch by just calling stg rename <new-patch-name>

Subject: [StGit PATCH] Allow renaming of the top-most branch by just calling stg rename <new-patch-name>

## tl;dr

10 messages between Feb 17, 2008 and Feb 23, 2008. Diffs are folded; open one to read it.

replies: 9people: 2as markdown or json

Onno Kortmann· Feb 17, 2008, 21:03 UTC · lore

instead of stg rename <old> <new>. This is for example helpful for those people who always have a typo or two in their patch names. ---

 stgit/commands/rename.py |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
Show changes to stgit/commands/rename.py +15 −5
diff --git a/stgit/commands/rename.py b/stgit/commands/rename.py
index e2b0fa4..acdf962 100644
--- a/stgit/commands/rename.py
+++ b/stgit/commands/rename.py
@@ -25,9 +25,10 @@ from stgit import stack, git
 
 
 help = 'rename a patch in the series'
-usage = """%prog [options] <oldpatch> <newpatch>
+usage = """%prog [options] [oldpatch] <newpatch>
 
-Rename <oldpatch> into <newpatch> in a series."""
+Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not given, 
the
+top-most patch will be renamed. """
 
 directory = DirectoryHasRepository()
 options = [make_option('-b', '--branch',
@@ -37,9 +38,18 @@ options = [make_option('-b', '--branch',
 def func(parser, options, args):
     """Rename a patch in the series
     """
-    if len(args) != 2:
-        parser.error('incorrect number of arguments')
+    crt=crt_series.get_current()
+
+    if len(args) == 2:
+        out.start('Renaming patch "%s" to "%s"' % (args[0], args[1]))
+
+    elif len(args) == 1:
+        if not crt:
+            raise CmdException, "No applied top patch to rename exists."
+        args=[crt]+args
+        out.start('Renaming top-most patch "%s" to "%s"' % (args[0], 
args[1]))
+    
+    else: parser.error('incorrect number of arguments')
 
-    out.start('Renaming patch "%s" to "%s"' % (args[0], args[1]))
     crt_series.rename_patch(args[0], args[1])
     out.done()
Karl Hasselström· Feb 18, 2008, 14:00 UTC · re: Onno Kortmann · lore

Re: [StGit PATCH] Allow renaming of the top-most branch by just calling stg rename <new-patch-name>

This is a good idea, I think.
On 2008-02-17 22:03:55 +0100, Onno Kortmann wrote:
> instead of stg rename <old> <new>. This is for example helpful for
> those people who always have a typo or two in their patch names.

Please follow the commit message conventions. That is, first one short summary line, then a blank line and the rest of the commit message. And a sign-off.

(Read git's Documentation/SubmittingPatches if you want the details.)
> +        args=[crt]+args
> +        out.start('Renaming top-most patch "%s" to "%s"' % (args[0], 
> args[1]))

Please consider storing the patch names in two suitably named variables, like this:

  if len(args) == 1:
     old, [new] = crt, args
  elif len(args) == 2:
     old, new = args
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Onno Kortmann· Feb 21, 2008, 21:30 UTC · re: Karl Hasselström · lore

Re: [StGit PATCH] Allow renaming of the top-most branch by just calling stg rename <new-patch-name>

Hi,
Show 6 quoted lines
> > instead of stg rename <old> <new>. This is for example helpful for
> > those people who always have a typo or two in their patch names.
> 
> Please follow the commit message conventions. That is, first one short
> summary line, then a blank line and the rest of the commit message.
> And a sign-off.
Ok, I tried to do this, I'm not used at all to sending patches with (st)git :-)
Thanks for the pointer and the assistance. Hopefully, --refid works as I 
understand it and the new patches appear in this thread.
 
> Please consider storing the patch names in two suitably named
> variables, like this:
I fixed that one, too.
I'll send out another patch, a test case for the stg rename command.
Greetings,
Onno
Karl Hasselström· Feb 22, 2008, 07:38 UTC · re: Onno Kortmann · lore

Re: [StGit PATCH] Allow renaming of the top-most branch by just calling stg rename <new-patch-name>

On 2008-02-21 22:30:56 +0100, Onno Kortmann wrote:
> Ok, I tried to do this, I'm not used at all to sending patches with
> (st)git :-) Thanks for the pointer and the assistance.
No problem. Thanks for writing the patches!
> Hopefully, --refid works as I understand it and the new patches
> appear in this thread.

Mailing patches to yourself is a good way to try things out if you're not sure they're going to work (but you seem to have had no problems with it).

> I'll send out another patch, a test case for the stg rename command.

Thanks, I'll pick both of them up, probably tomorrow (unless Catalin does so first).

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Onno Kortmann· Feb 22, 2008, 22:52 UTC · re: Karl Hasselström · lore

Re: [StGit PATCH] Allow renaming of the top-most branch by just calling stg rename <new-patch-name>

Hi 
> Mailing patches to yourself is a good way to try things out if you're
> not sure they're going to work (but you seem to have had no problems
> with it).
Yes, I did that and it worked so I figured it would be ok to do it in public.. :)
> Thanks, I'll pick both of them up, probably tomorrow (unless Catalin
> does so first).

Ok - to answer both other mails here, of course I'm fine with all the changes in both patches.

Greetings,
Onno
Karl Hasselström· Feb 23, 2008, 07:45 UTC · re: Onno Kortmann · lore

Re: [StGit PATCH] Allow renaming of the top-most branch by just calling stg rename <new-patch-name>

On 2008-02-22 23:52:52 +0100, Onno Kortmann wrote:
> Ok - to answer both other mails here, of course I'm fine with all
> the changes in both patches.

Well it never hurts to ask. I've heard that some people feel strongly about these style issues, complaining about other people's patches and whatnot. ;-)

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Onno Kortmann· Feb 21, 2008, 21:42 UTC · re: Karl Hasselström · lore

[PATCH 1/2] Simple rename of top-most patch

Allow renaming of the top-most patch just by calling stg rename <new-patch-name>, instead of stg rename <old> <new>. This is for example helpful for those people who always have a typo or two in their patch names.

Signed-off-by: Onno Kortmann <onno@gmx.net>
---
 stgit/commands/rename.py |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
Show changes to stgit/commands/rename.py +16 −7
diff --git a/stgit/commands/rename.py b/stgit/commands/rename.py
index e2b0fa4..c687455 100644
--- a/stgit/commands/rename.py
+++ b/stgit/commands/rename.py
@@ -25,9 +25,10 @@ from stgit import stack, git
 
 
 help = 'rename a patch in the series'
-usage = """%prog [options] <oldpatch> <newpatch>
+usage = """%prog [options] [oldpatch] <newpatch>
 
-Rename <oldpatch> into <newpatch> in a series."""
+Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not given, the
+top-most patch will be renamed. """
 
 directory = DirectoryHasRepository()
 options = [make_option('-b', '--branch',
@@ -37,9 +38,17 @@ options = [make_option('-b', '--branch',
 def func(parser, options, args):
     """Rename a patch in the series
     """
-    if len(args) != 2:
-        parser.error('incorrect number of arguments')
-
-    out.start('Renaming patch "%s" to "%s"' % (args[0], args[1]))
-    crt_series.rename_patch(args[0], args[1])
+    crt=crt_series.get_current()
+
+    if len(args) == 2:
+        old, new=args
+    elif len(args) == 1:
+        if not crt:
+            raise CmdException, "No applied top patch to rename exists."
+        old, [new]=crt, args
+    else: parser.error('incorrect number of arguments')
+
+    out.start('Renaming patch "%s" to "%s"' % (old, new))
+    crt_series.rename_patch(old, new)
+    
     out.done()
Karl Hasselström· Feb 22, 2008, 07:44 UTC · re: Onno Kortmann · lore

Re: [PATCH 1/2] Simple rename of top-most patch

On 2008-02-21 22:42:51 +0100, Onno Kortmann wrote:
Show 6 quoted lines
> +    if len(args) == 2:
> +        old, new=args
> +    elif len(args) == 1:
> +        if not crt:
> +            raise CmdException, "No applied top patch to rename exists."
> +        old, [new]=crt, args

I think the style throughout StGit is to have spaces arond operators. No biggie, though -- I'll fix it up.

> +    else: parser.error('incorrect number of arguments')

It looks strange without a line break here, especially since there are line breaks in the if and elif branches. I'll fix this too if you don't mind.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Onno Kortmann· Feb 21, 2008, 21:43 UTC · re: Karl Hasselström · lore

[PATCH 2/2] Test the 'stg rename' command

This just tests the few basic cases of the stg rename command.
Signed-off-by: Onno Kortmann <onno@gmx.net>
---
 t/t2900-rename.sh |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
 create mode 100755 t/t2900-rename.sh
Show changes to t/t2900-rename.sh +47 −0
diff --git a/t/t2900-rename.sh b/t/t2900-rename.sh
new file mode 100755
index 0000000..a8f8f0b
--- /dev/null
+++ b/t/t2900-rename.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Onno Kortmann
+# Parts taken from the other test scripts
+# in this directory.
+#
+
+test_description='stg rename test
+
+Tests some parts of the stg rename command.'
+
+. ./test-lib.sh
+stg init
+
+test_expect_success 'Rename in empty' '
+   ! stg rename foo
+'
+
+test_expect_success 'Rename single top-most' '
+   stg new -m foo
+   stg rename bar
+'
+# bar
+
+test_expect_success 'Rename non-existing' '
+   ! stg rename neithersuchpatch norsuchpatch
+'
+
+test_expect_success 'Rename with two arguments' '
+   stg new -m baz
+   stg rename bar foo
+'
+# foo,baz
+
+test_expect_success 'Rename to existing name' '
+   ! stg rename foo baz
+'
+
+test_expect_success 'Rename to same name' '
+   ! stg rename foo foo
+'
+
+test_expect_success 'Rename top-most when others exist' '
+   stg rename bar
+'
+
+test_done
Karl Hasselström· Feb 22, 2008, 07:48 UTC · re: Onno Kortmann · lore

Re: [PATCH 2/2] Test the 'stg rename' command

On 2008-02-21 22:43:18 +0100, Onno Kortmann wrote:
> +test_expect_success 'Rename with two arguments' '
> +   stg new -m baz
> +   stg rename bar foo
> +'

You want "&&" at the end of every line but the last one, otherwise errors in any line but the last won't be caught. I'll add that, if you don't mind.

> +test_expect_success 'Rename to existing name' '
> +   ! stg rename foo baz
> +'

You remembered to use test_expect_success and ! instead of test_expect_failure -- good!

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

← back to recent threads