{"thread":{"id":"5828","subject":"[StGIT PATCH] Command to move a patch to the top","startedAt":"2006-10-05T21:14:28Z","lastAt":"2006-10-05T21:14:28Z","messageCount":1,"participants":["Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"28255","messageId":"20061005211428.17126.50031.stgit@lathund.dewire.com","threadId":"5828","inReplyTo":"20061005211414.17126.64563.stgit@lathund.dewire.com","subject":"[StGIT PATCH] Command to move a patch to the top","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2006-10-05T21:14:28Z","receivedAt":"2006-10-05T21:14:28Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"From: Robin Rosenberg <robin.rosenberg@dewire.com>\n\n\n---\n\n stgit/commands/float.py |   78 +++++++++++++++++++++++++++++++++++++++++++++++\n stgit/main.py           |    3 ++\n t/t1500-float.sh        |   56 ++++++++++++++++++++++++++++++++++\n 3 files changed, 137 insertions(+), 0 deletions(-)\n\ndiff --git a/stgit/commands/float.py b/stgit/commands/float.py\nnew file mode 100644\nindex 0000000..3e39b35\n--- /dev/null\n+++ b/stgit/commands/float.py\n@@ -0,0 +1,78 @@\n+\n+__copyright__ = \"\"\"\n+Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.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+help = 'push a patch to the top, even if applied'\n+usage = \"\"\"%prog [options]\n+\n+Push a patch to the top even if applied. The necessary\n+pop and push operations will be performed to accomplish\n+this. \"\"\"\n+\n+#options = [make_option('-b', '--branch',\n+#                       help = 'use BRANCH instead of the default one')].\n+\n+options = [make_option('-a', '--all',\n+                       help = 'push all the unapplied patches',\n+                       action = 'store_true'),\n+           make_option('--keep',\n+                       help = 'keep the current working directory',\n+                       action = 'store_true'),\n+           make_option('-m', '--merged',\n+                       help = 'check for patches merged upstream',\n+                       action = 'store_true') ]\n+           \n+def func(parser, options, args):\n+    \"\"\"Pops and pushed to make the named patch the topmost patch\n+    \"\"\"\n+\n+    if not options.keep:\n+        check_local_changes()\n+        check_conflicts()\n+        check_head_top_equal()\n+\n+    unapplied = crt_series.get_unapplied()\n+    applied = crt_series.get_applied()\n+    all = []\n+    all.extend(unapplied)\n+    all.extend(applied)\n+\n+    patches = parse_patches(args, all)\n+\n+    topush=[]\n+    topop=[]\n+\n+    for p in patches:\n+        while p in applied:\n+            top = applied[-1]\n+            print applied\n+            if not top in patches:\n+                topush.insert(0,top)\n+            topop.append(top)\n+            x = applied.pop()\n+    for p in patches:\n+        topush.append(p)\n+\n+    pop_patches(topop, options.keep)\n+    push_patches(topush, options.merged)\ndiff --git a/stgit/main.py b/stgit/main.py\nindex f59bce6..e9cc6cd 100644\n--- a/stgit/main.py\n+++ b/stgit/main.py\n@@ -38,6 +38,7 @@ import stgit.commands.clone\n import stgit.commands.commit\n import stgit.commands.export\n import stgit.commands.files\n+import stgit.commands.float\n import stgit.commands.fold\n import stgit.commands.goto\n import stgit.commands.id\n@@ -77,6 +78,7 @@ commands = {\n     'commit':   stgit.commands.commit,\n     'export':   stgit.commands.export,\n     'files':    stgit.commands.files,\n+    'float':    stgit.commands.float,\n     'fold':     stgit.commands.fold,\n     'goto':     stgit.commands.goto,\n     'id':       stgit.commands.id,\n@@ -113,6 +115,7 @@ stackcommands = (\n     'applied',\n     'clean',\n     'commit',\n+    'float',\n     'goto',\n     'init',\n     'pop',\ndiff --git a/t/t1500-float.sh b/t/t1500-float.sh\nnew file mode 100755\nindex 0000000..dbcd8ce\n--- /dev/null\n+++ b/t/t1500-float.sh\n@@ -0,0 +1,56 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2006 Robin Rosenberg\n+#\n+\n+test_description='Test floating a number of patches to the top of the stack\n+\n+'\n+\n+. ./test-lib.sh\n+\n+test_expect_success \\\n+\t'Initialize the StGIT repository' \\\n+\t'stg init &&\n+\t stg new A -m \"a\" && echo A >a.txt && stg add a.txt && stg refresh &&\n+\t stg new B -m \"b\" && echo B >b.txt && stg add b.txt && stg refresh &&\n+\t stg new C -m \"c\" && echo C >c.txt && stg add c.txt && stg refresh &&\n+\t stg new D -m \"d\" && echo D >d.txt && stg add d.txt && stg refresh &&\n+\t stg new E -m \"e\" && echo E >e.txt && stg add e.txt && stg refresh &&\n+\t stg new F -m \"f\" && echo F >f.txt && stg add f.txt && stg refresh &&\n+\t stg new G -m \"g\" && echo G >g.txt && stg add g.txt && stg refresh &&\n+\t stg pop &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"A B C D E F\"\n+\t'\n+\n+test_expect_success \\\n+\t'Float A to top' \\\n+\t'stg float A &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"B C D E F A\"\n+\t'\n+test_expect_success \\\n+\t'Float A to top (noop)' \\\n+\t'stg float A &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"B C D E F A\"\n+\t'\n+test_expect_success \\\n+\t'Float B C to top' \\\n+\t'stg float B C &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"D E F A B C\"\n+\t'\n+test_expect_success \\\n+\t'Float E A to top' \\\n+\t'stg float E A &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"D F B C E A\"\n+\t'\n+test_expect_success \\\n+\t'Float E to top' \\\n+\t'stg float E &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"D F B C A E\"\n+\t'\n+test_expect_success \\\n+\t'Float G F to top' \\\n+\t'stg float G F &&\n+\t test \"`echo \\`cat .git/patches/master/applied\\``\" = \"D B C A E G F\"\n+\t'\n+test_done\n"}]}