{"thread":{"id":"6454","subject":"[PATCH] Add new 'rebase' command.","startedAt":"2007-01-20T15:46:50Z","lastAt":"2007-01-20T15:46:50Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32158","messageId":"20070120154504.19466.87132.stgit@gandelf.nowhere.earth","threadId":"6454","inReplyTo":null,"subject":"[PATCH] Add new 'rebase' command.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-01-20T15:46:50Z","receivedAt":"2007-01-20T15:46:50Z","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\nThis patch uses the \"rebase --to <target>\" syntax, which leaves room\nfor the feature suggeted by Jakub to use \"rebase <stack>\" to rebase a\nstack onto current branch.\n\n stgit/commands/rebase.py |   69 ++++++++++++++++++++++++++++++++++++++++++++++\n stgit/main.py            |    1 +\n t/t2200-rebase.sh        |   33 ++++++++++++++++++++++\n 3 files changed, 103 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..8bf233c 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',\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"}]}