Allow renaming of the top-most branch by just calling stg rename <new-patch-name>
PATCH 1/1 Allow renaming of the top-most branch by just 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.
---
stgit/commands/rename.py | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-)
stgit/commands/rename.py +2 -2
@@ -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()This is a good idea, I think.
Quoted 2 lines · Onno Kortmann
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.)
Quoted 3 lines
(quoted diff) +2
-0+ 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
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Hi,
Quoted 6 lines
Quoted 2 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.
Quoted 2 lines
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
Quoted 2 lines · Onno Kortmann
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!
Quoted 2 lines
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).
Quoted 1 line
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).
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/2 Simple rename of top-most patch
In reply to Karl HasselströmAllow 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.
---
stgit/commands/rename.py | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-)
stgit/commands/rename.py +16 -7
@@ -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()
Re: [PATCH 1/2] Simple rename of top-most patch
stgit/commands/rename.py options = [make_option('-b', '--branch', · line 48
Quoted 6 lines · Onno Kortmann
stgit/commands/rename.py +6
-0+ 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.
Quoted 1 line
+ 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.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 2/2 Test the 'stg rename' command
In reply to Karl HasselströmThis just tests the few basic cases of the stg rename command.
---
t/t2900-rename.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-) create mode 100755 t/t2900-rename.sh
t/t2900-rename.sh new file +47 -0
@@ -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
Re: [PATCH 2/2] Test the 'stg rename' command
t/t2900-rename.sh line 32
Quoted 4 lines · Onno Kortmann
t/t2900-rename.sh new file +4
-0+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.
t/t2900-rename.sh line 37
Quoted 3 lines
t/t2900-rename.sh new file +3
-0+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!
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Hi
Quoted 3 lines
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.. :)
Quoted 2 lines
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
Quoted 2 lines · Onno Kortmann
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. ;-)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle