{"thread":{"id":"6455","subject":"[PATCH] Add new 'rebase' command.","startedAt":"2007-01-20T18:04:21Z","lastAt":"2007-01-21T23:37:14Z","messageCount":4,"participants":["Yann Dirson","Catalin Marinas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32160","messageId":"20070120180329.22621.30534.stgit@gandelf.nowhere.earth","threadId":"6455","inReplyTo":null,"subject":"[PATCH] Add new 'rebase' command.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-01-20T18:04:21Z","receivedAt":"2007-01-20T18:04:21Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"\n\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\nTake two: I had forgotten to add \"rebase\" to the list of stack\ncommands for the purpose of help.\n\n stgit/commands/rebase.py |   69 ++++++++++++++++++++++++++++++++++++++++++++++\n stgit/main.py            |    2 +\n t/t2200-rebase.sh        |   33 ++++++++++++++++++++++\n 3 files changed, 104 insertions(+), 0 deletions(-)\n\ndiff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py\nnew file mode 100644\nindex 0000000..79d67a7\n--- /dev/null\n+++ b/stgit/commands/rebase.py\n@@ -0,0 +1,69 @@\n+__copyright__ = \"\"\"\n+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>\n+\n+This program is free software; you can redistribute it and/or modify\n+it under the terms of the GNU General Public License version 2 as\n+published by the Free Software Foundation.\n+\n+This program is distributed in the hope that it will be useful,\n+but WITHOUT ANY WARRANTY; without even the implied warranty of\n+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+GNU General Public License for more details.\n+\n+You should have received a copy of the GNU General Public License\n+along with this program; if not, write to the Free Software\n+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n+\"\"\"\n+\n+import sys, os\n+from optparse import OptionParser, make_option\n+\n+from stgit.commands.common import *\n+from stgit.utils import *\n+from stgit import stack, git\n+\n+\n+help = 'move the stack base to another point in history'\n+usage = \"\"\"%prog [options] --to <target-commit>\n+\n+Pop all patches from current stack, move the stack base to the\n+given <target-commit>, and push the patches back.\"\"\"\n+\n+options = [make_option('-n', '--nopush',\n+                       help = 'do not push the patches back after pulling',\n+                       action = 'store_true'),\n+           make_option('--to', metavar = 'COMMITID',\n+                       help = 'move the stack base to COMMITID')]\n+\n+def func(parser, options, args):\n+    \"\"\"Rebase the current stack\n+    \"\"\"\n+    if len(args) > 0:\n+        parser.error('incorrect number of arguments')\n+\n+    if not options.to:\n+        parser.error('rebase requires option --to')\n+\n+    if crt_series.get_protected():\n+        raise CmdException, 'This branch is protected. Rebase is not permitted'\n+\n+    check_local_changes()\n+    check_conflicts()\n+    check_head_top_equal()\n+\n+    # pop all patches\n+    applied = crt_series.get_applied()\n+    if len(applied) > 0:\n+        print 'Popping all applied patches...',\n+        sys.stdout.flush()\n+        crt_series.pop_patch(applied[0])\n+        print 'done'\n+\n+    print 'Rebasing to \"%s\"...' % options.to\n+    git.reset(tree_id = git_id(options.to))\n+\n+    # push the patches back\n+    if not options.nopush:\n+        push_patches(applied)\n+\n+    print_crt_patch()\ndiff --git a/stgit/main.py b/stgit/main.py\nindex 0f92f75..ca2bbde 100644\n--- a/stgit/main.py\n+++ b/stgit/main.py\n@@ -80,6 +80,7 @@ commands = Commands({\n     'pop':              'pop',\n     'pull':             'pull',\n     'push':             'push',\n+    'rebase':           'rebase',\n     'refresh':          'refresh',\n     'rename':           'rename',\n     'resolved':         'resolved',\n@@ -110,6 +111,7 @@ stackcommands = (\n     'init',\n     'pop',\n     'push',\n+    'rebase',\n     'series',\n     'top',\n     'unapplied',\ndiff --git a/t/t2200-rebase.sh b/t/t2200-rebase.sh\nnew file mode 100755\nindex 0000000..6211cbd\n--- /dev/null\n+++ b/t/t2200-rebase.sh\n@@ -0,0 +1,33 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Yann Dirson\n+#\n+\n+test_description='Test the \"rebase\" command.'\n+\n+. ./test-lib.sh\n+\n+test_expect_success \\\n+\t'Setup a multi-commit branch and fork an stgit stack' \\\n+\t'\n+\techo foo > file1 &&\n+\tgit add file1 &&\n+\tgit commit -m a &&\n+\techo foo > file2 &&\n+\tgit add file2 &&\n+\tgit commit -m b &&\n+\n+\tstg branch --create stack &&\n+\tstg new p -m . &&\n+\techo bar >> file1 &&\n+\tstg refresh\n+\t'\n+\n+test_expect_success \\\n+\t'Rebase to previous commit' \\\n+\t'\n+\tstg rebase --to master~1 &&\n+\ttest `git rev-parse bases/stack` = `git rev-parse master~1`\n+\t'\n+\n+test_done\n"},{"id":"32240","messageId":"b0943d9e0701211500v2f54aa61k2592ba060131318@mail.gmail.com","threadId":"6455","inReplyTo":"20070120180329.22621.30534.stgit@gandelf.nowhere.earth","subject":"Re: [PATCH] Add new 'rebase' command.","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2007-01-21T23:00:57Z","receivedAt":"2007-01-21T23:00:57Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 20/01/07, Yann Dirson <ydirson@altern.org> wrote:\n> Take two: I had forgotten to add \"rebase\" to the list of stack\n> commands for the purpose of help.\n\nThanks for the patch. I also added the command to the stgit-completion.bash.\n\nI applied it but changed the patch a bit so that there is no need for\nthe --to option. I understood your point but I find it a bit strange\nto have this mandatory option. Anyway, command line syntax doesn't\nhave to follow the natural language exactly :-).\n\nRegards.\n\n-- \nCatalin\n"},{"id":"32243","messageId":"20070121232618.GD4665@nan92-1-81-57-214-146.fbx.proxad.net","threadId":"6455","inReplyTo":"b0943d9e0701211500v2f54aa61k2592ba060131318@mail.gmail.com","subject":"Re: [PATCH] Add new 'rebase' command.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-01-21T23:26:18Z","receivedAt":"2007-01-21T23:26:18Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"On Sun, Jan 21, 2007 at 11:00:57PM +0000, Catalin Marinas wrote:\n> On 20/01/07, Yann Dirson <ydirson@altern.org> wrote:\n> >Take two: I had forgotten to add \"rebase\" to the list of stack\n> >commands for the purpose of help.\n> \n> Thanks for the patch. I also added the command to the stgit-completion.bash.\n> \n> I applied it but changed the patch a bit so that there is no need for\n> the --to option. I understood your point but I find it a bit strange\n> to have this mandatory option. Anyway, command line syntax doesn't\n> have to follow the natural language exactly :-).\n\nWell, I thought the natural next patch to this command would be,\naccording to the discussions with Jakub, to make first \"--to target\"\noptional, as a natural replacement for \"stg pull . <target>\" when the\ntarget is the parent branch, and then possibly add the ability of\nrunning rebase from the target branch as also sugested by Jakub,\nleading to the natural \"rebase [<stack>|--to <target>]\" syntax.\n\nAlthough I'm not sure we'll do that in the near future, removing the\nneed for --to would somewhat get in the way of this possibility.\n\nBest regards,\n-- \nYann.\n"},{"id":"32246","messageId":"b0943d9e0701211537oac61eceq48d45501193e6790@mail.gmail.com","threadId":"6455","inReplyTo":"20070121232618.GD4665@nan92-1-81-57-214-146.fbx.proxad.net","subject":"Re: [PATCH] Add new 'rebase' command.","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2007-01-21T23:37:14Z","receivedAt":"2007-01-21T23:37:14Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 21/01/07, Yann Dirson <ydirson@altern.org> wrote:\n> On Sun, Jan 21, 2007 at 11:00:57PM +0000, Catalin Marinas wrote:\n> > I applied it but changed the patch a bit so that there is no need for\n> > the --to option. I understood your point but I find it a bit strange\n> > to have this mandatory option. Anyway, command line syntax doesn't\n> > have to follow the natural language exactly :-).\n>\n> Well, I thought the natural next patch to this command would be,\n> according to the discussions with Jakub, to make first \"--to target\"\n> optional, as a natural replacement for \"stg pull . <target>\" when the\n> target is the parent branch, and then possibly add the ability of\n> running rebase from the target branch as also sugested by Jakub,\n> leading to the natural \"rebase [<stack>|--to <target>]\" syntax.\n>\n> Although I'm not sure we'll do that in the near future, removing the\n> need for --to would somewhat get in the way of this possibility.\n\nI'll go through the other e-mails tomorrow (too late here) and either\nadd the option back or come with counter arguments :-)\n\n-- \nCatalin\n"}]}