* [PATCH] Add new 'rebase' command.
@ 2007-01-20 15:46 Yann Dirson
0 siblings, 0 replies; 5+ messages in thread
From: Yann Dirson @ 2007-01-20 15:46 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
This patch uses the "rebase --to <target>" syntax, which leaves room
for the feature suggeted by Jakub to use "rebase <stack>" to rebase a
stack onto current branch.
stgit/commands/rebase.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++
stgit/main.py | 1 +
t/t2200-rebase.sh | 33 ++++++++++++++++++++++
3 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py
new file mode 100644
index 0000000..79d67a7
--- /dev/null
+++ b/stgit/commands/rebase.py
@@ -0,0 +1,69 @@
+__copyright__ = """
+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys, os
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'move the stack base to another point in history'
+usage = """%prog [options] --to <target-commit>
+
+Pop all patches from current stack, move the stack base to the
+given <target-commit>, and push the patches back."""
+
+options = [make_option('-n', '--nopush',
+ help = 'do not push the patches back after pulling',
+ action = 'store_true'),
+ make_option('--to', metavar = 'COMMITID',
+ help = 'move the stack base to COMMITID')]
+
+def func(parser, options, args):
+ """Rebase the current stack
+ """
+ if len(args) > 0:
+ parser.error('incorrect number of arguments')
+
+ if not options.to:
+ parser.error('rebase requires option --to')
+
+ if crt_series.get_protected():
+ raise CmdException, 'This branch is protected. Rebase is not permitted'
+
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal()
+
+ # pop all patches
+ applied = crt_series.get_applied()
+ if len(applied) > 0:
+ print 'Popping all applied patches...',
+ sys.stdout.flush()
+ crt_series.pop_patch(applied[0])
+ print 'done'
+
+ print 'Rebasing to "%s"...' % options.to
+ git.reset(tree_id = git_id(options.to))
+
+ # push the patches back
+ if not options.nopush:
+ push_patches(applied)
+
+ print_crt_patch()
diff --git a/stgit/main.py b/stgit/main.py
index 0f92f75..8bf233c 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -80,6 +80,7 @@ commands = Commands({
'pop': 'pop',
'pull': 'pull',
'push': 'push',
+ 'rebase': 'rebase',
'refresh': 'refresh',
'rename': 'rename',
'resolved': 'resolved',
diff --git a/t/t2200-rebase.sh b/t/t2200-rebase.sh
new file mode 100755
index 0000000..6211cbd
--- /dev/null
+++ b/t/t2200-rebase.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Yann Dirson
+#
+
+test_description='Test the "rebase" command.'
+
+. ./test-lib.sh
+
+test_expect_success \
+ 'Setup a multi-commit branch and fork an stgit stack' \
+ '
+ echo foo > file1 &&
+ git add file1 &&
+ git commit -m a &&
+ echo foo > file2 &&
+ git add file2 &&
+ git commit -m b &&
+
+ stg branch --create stack &&
+ stg new p -m . &&
+ echo bar >> file1 &&
+ stg refresh
+ '
+
+test_expect_success \
+ 'Rebase to previous commit' \
+ '
+ stg rebase --to master~1 &&
+ test `git rev-parse bases/stack` = `git rev-parse master~1`
+ '
+
+test_done
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] Add new 'rebase' command.
@ 2007-01-20 18:04 Yann Dirson
2007-01-21 23:00 ` Catalin Marinas
0 siblings, 1 reply; 5+ messages in thread
From: Yann Dirson @ 2007-01-20 18:04 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
Take two: I had forgotten to add "rebase" to the list of stack
commands for the purpose of help.
stgit/commands/rebase.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++
stgit/main.py | 2 +
t/t2200-rebase.sh | 33 ++++++++++++++++++++++
3 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py
new file mode 100644
index 0000000..79d67a7
--- /dev/null
+++ b/stgit/commands/rebase.py
@@ -0,0 +1,69 @@
+__copyright__ = """
+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys, os
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'move the stack base to another point in history'
+usage = """%prog [options] --to <target-commit>
+
+Pop all patches from current stack, move the stack base to the
+given <target-commit>, and push the patches back."""
+
+options = [make_option('-n', '--nopush',
+ help = 'do not push the patches back after pulling',
+ action = 'store_true'),
+ make_option('--to', metavar = 'COMMITID',
+ help = 'move the stack base to COMMITID')]
+
+def func(parser, options, args):
+ """Rebase the current stack
+ """
+ if len(args) > 0:
+ parser.error('incorrect number of arguments')
+
+ if not options.to:
+ parser.error('rebase requires option --to')
+
+ if crt_series.get_protected():
+ raise CmdException, 'This branch is protected. Rebase is not permitted'
+
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal()
+
+ # pop all patches
+ applied = crt_series.get_applied()
+ if len(applied) > 0:
+ print 'Popping all applied patches...',
+ sys.stdout.flush()
+ crt_series.pop_patch(applied[0])
+ print 'done'
+
+ print 'Rebasing to "%s"...' % options.to
+ git.reset(tree_id = git_id(options.to))
+
+ # push the patches back
+ if not options.nopush:
+ push_patches(applied)
+
+ print_crt_patch()
diff --git a/stgit/main.py b/stgit/main.py
index 0f92f75..ca2bbde 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -80,6 +80,7 @@ commands = Commands({
'pop': 'pop',
'pull': 'pull',
'push': 'push',
+ 'rebase': 'rebase',
'refresh': 'refresh',
'rename': 'rename',
'resolved': 'resolved',
@@ -110,6 +111,7 @@ stackcommands = (
'init',
'pop',
'push',
+ 'rebase',
'series',
'top',
'unapplied',
diff --git a/t/t2200-rebase.sh b/t/t2200-rebase.sh
new file mode 100755
index 0000000..6211cbd
--- /dev/null
+++ b/t/t2200-rebase.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Yann Dirson
+#
+
+test_description='Test the "rebase" command.'
+
+. ./test-lib.sh
+
+test_expect_success \
+ 'Setup a multi-commit branch and fork an stgit stack' \
+ '
+ echo foo > file1 &&
+ git add file1 &&
+ git commit -m a &&
+ echo foo > file2 &&
+ git add file2 &&
+ git commit -m b &&
+
+ stg branch --create stack &&
+ stg new p -m . &&
+ echo bar >> file1 &&
+ stg refresh
+ '
+
+test_expect_success \
+ 'Rebase to previous commit' \
+ '
+ stg rebase --to master~1 &&
+ test `git rev-parse bases/stack` = `git rev-parse master~1`
+ '
+
+test_done
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Add new 'rebase' command.
2007-01-20 18:04 Yann Dirson
@ 2007-01-21 23:00 ` Catalin Marinas
2007-01-21 23:26 ` Yann Dirson
0 siblings, 1 reply; 5+ messages in thread
From: Catalin Marinas @ 2007-01-21 23:00 UTC (permalink / raw)
To: Yann Dirson; +Cc: git
On 20/01/07, Yann Dirson <ydirson@altern.org> wrote:
> Take two: I had forgotten to add "rebase" to the list of stack
> commands for the purpose of help.
Thanks for the patch. I also added the command to the stgit-completion.bash.
I applied it but changed the patch a bit so that there is no need for
the --to option. I understood your point but I find it a bit strange
to have this mandatory option. Anyway, command line syntax doesn't
have to follow the natural language exactly :-).
Regards.
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Add new 'rebase' command.
2007-01-21 23:00 ` Catalin Marinas
@ 2007-01-21 23:26 ` Yann Dirson
2007-01-21 23:37 ` Catalin Marinas
0 siblings, 1 reply; 5+ messages in thread
From: Yann Dirson @ 2007-01-21 23:26 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
On Sun, Jan 21, 2007 at 11:00:57PM +0000, Catalin Marinas wrote:
> On 20/01/07, Yann Dirson <ydirson@altern.org> wrote:
> >Take two: I had forgotten to add "rebase" to the list of stack
> >commands for the purpose of help.
>
> Thanks for the patch. I also added the command to the stgit-completion.bash.
>
> I applied it but changed the patch a bit so that there is no need for
> the --to option. I understood your point but I find it a bit strange
> to have this mandatory option. Anyway, command line syntax doesn't
> have to follow the natural language exactly :-).
Well, I thought the natural next patch to this command would be,
according to the discussions with Jakub, to make first "--to target"
optional, as a natural replacement for "stg pull . <target>" when the
target is the parent branch, and then possibly add the ability of
running rebase from the target branch as also sugested by Jakub,
leading to the natural "rebase [<stack>|--to <target>]" syntax.
Although I'm not sure we'll do that in the near future, removing the
need for --to would somewhat get in the way of this possibility.
Best regards,
--
Yann.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Add new 'rebase' command.
2007-01-21 23:26 ` Yann Dirson
@ 2007-01-21 23:37 ` Catalin Marinas
0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2007-01-21 23:37 UTC (permalink / raw)
To: Yann Dirson; +Cc: git
On 21/01/07, Yann Dirson <ydirson@altern.org> wrote:
> On Sun, Jan 21, 2007 at 11:00:57PM +0000, Catalin Marinas wrote:
> > I applied it but changed the patch a bit so that there is no need for
> > the --to option. I understood your point but I find it a bit strange
> > to have this mandatory option. Anyway, command line syntax doesn't
> > have to follow the natural language exactly :-).
>
> Well, I thought the natural next patch to this command would be,
> according to the discussions with Jakub, to make first "--to target"
> optional, as a natural replacement for "stg pull . <target>" when the
> target is the parent branch, and then possibly add the ability of
> running rebase from the target branch as also sugested by Jakub,
> leading to the natural "rebase [<stack>|--to <target>]" syntax.
>
> Although I'm not sure we'll do that in the near future, removing the
> need for --to would somewhat get in the way of this possibility.
I'll go through the other e-mails tomorrow (too late here) and either
add the option back or come with counter arguments :-)
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-01-21 23:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-20 15:46 [PATCH] Add new 'rebase' command Yann Dirson
-- strict thread matches above, loose matches on Subject: below --
2007-01-20 18:04 Yann Dirson
2007-01-21 23:00 ` Catalin Marinas
2007-01-21 23:26 ` Yann Dirson
2007-01-21 23:37 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).