git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 6/7] Add a "--clone" option to "stg branch"

From
CLChuck Lever <cel@netapp.com>
Date
Nov 29, 2005, 22:09 UTC
Message-ID
<20051129220949.9885.51533.stgit@dexter.citi.umich.edu>
In-Reply-To
<20051129220552.9885.41086.stgit@dexter.citi.umich.edu>

Cloning a branch means creating a new branch and copying all of the original branch's patches and its base to it. Like creating a tag, but this also preserves all the StGIT patches as well.

Signed-off-by: Chuck Lever <cel@netapp.com>
---
 stgit/commands/branch.py |   28 +++++++++++++++++++++++++---
 stgit/stack.py           |   35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index ccf1f6b..5bc5e94 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -18,7 +18,7 @@ along with this program; if not, write t
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
+import sys, os, time
 from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
@@ -29,10 +29,10 @@ from stgit import stack, git
 help = 'manage development branches'
 usage = """%prog [options] branch-name [commit-id]
 
-Create, list, switch between, rename, or delete development branches
+Create, clone, switch between, rename, or delete development branches
 within a git repository.  By default, a single branch called 'master'
 is always created in a new repository.  This subcommand allows you to
-manage several patch series in the same repository.
+manage several patch series in the same repository via GIT branches.
 
 When displaying the branches, the names can be prefixed with
 's' (StGIT managed) or 'p' (protected)."""
@@ -40,6 +40,9 @@ When displaying the branches, the names 
 options = [make_option('-c', '--create',
                        help = 'create a new development branch',
                        action = 'store_true'),
+           make_option('--clone',
+                       help = 'copy the contents of a branch',
+                       action = 'store_true'),
            make_option('--delete',
                        help = 'delete an existing development branch',
                        action = 'store_true'),
@@ -124,6 +127,25 @@ def func(parser, options, args):
         print 'Branch "%s" created.' % args[0]
         return
 
+    elif options.clone:
+
+        if len(args) == 0:
+            clone = crt_series.get_branch() + \
+                    time.strftime('-%C%y%m%d-%H%M%S')
+        elif len(args) == 1:
+            clone = args[0]
+        else:
+            parser.error('incorrect number of arguments')
+
+        check_local_changes()
+        check_conflicts()
+        check_head_top_equal()
+
+        print 'Cloning current branch to "%s"...' % clone
+        crt_series.clone(clone)
+        print 'done'
+        return
+
     elif options.delete:
 
         if len(args) != 1:
diff --git a/stgit/stack.py b/stgit/stack.py
index dc7c19f..2866121 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -18,7 +18,7 @@ along with this program; if not, write t
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
+import sys, os, shutil
 
 from stgit.utils import *
 from stgit import git
@@ -420,6 +420,39 @@ class Series:
 
         self.__init__(to_name)
 
+    def clone(self, target_series):
+        """Clones a series
+        """
+        base = read_string(self.get_base_file())
+        git.create_branch(target_series, tree_id = base)
+        Series(target_series).init()
+
+        new_series = Series(target_series)
+
+        if os.path.exists(self.__descr_file):
+            shutil.copyfile(self.__descr_file, new_series.__descr_file)
+
+        for p in self.get_applied():
+            patch = self.get_patch(p)
+            new_series.new_patch(p, message = patch.get_description(),
+                                 can_edit = False, unapplied = True,
+                                 bottom = patch.get_bottom(),
+                                 top = patch.get_top(),
+                                 author_name = patch.get_authname(),
+                                 author_email = patch.get_authemail(),
+                                 author_date = patch.get_authdate())
+            modified = new_series.push_patch(p)
+
+        for p in self.get_unapplied():
+            patch = self.get_patch(p)
+            new_series.new_patch(p, message = patch.get_description(),
+                                 can_edit = False, unapplied = True,
+                                 bottom = patch.get_bottom(),
+                                 top = patch.get_top(),
+                                 author_name = patch.get_authname(),
+                                 author_email = patch.get_authemail(),
+                                 author_date = patch.get_authdate())
+
     def delete(self, force = False):
         """Deletes an stgit series
         """
Previous: Chuck LeverNext: Catalin Marinas
Message 8 of 16 in “[PATCH 0/7]”
  1. 0/7 Chuck Lever, Nov 29, 2005
  2. 1/7 Make "stg export" save the base commit in the output directoryChuck Lever, Nov 29, 2005
  3. Catalin MarinasNov 30, 2005
  4. 2/7 Use git-rev-parse to find the local GIT repositoryChuck Lever, Nov 29, 2005
  5. 3/7 Align branch descriptions in output of "stg branch -l"Chuck Lever, Nov 29, 2005
  6. 4/7 "stg series" option to show patch summary descriptionsChuck Lever, Nov 29, 2005
  7. 5/7 Add facility to print short list of patches around 'top'Chuck Lever, Nov 29, 2005
  8. 6/7 Add a "--clone" option to "stg branch"Chuck Lever, Nov 29, 2005
  9. Catalin MarinasDec 1, 2005
  10. Chuck LeverDec 1, 2005
  11. 7/7 Use a separate directory for patches under each branch subdirChuck Lever, Nov 29, 2005
  12. Catalin MarinasNov 30, 2005
  13. Chuck LeverNov 30, 2005
  14. Catalin MarinasNov 30, 2005
  15. Chuck LeverDec 1, 2005
  16. Catalin MarinasNov 30, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.