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

[PATCH 5/6] Have 'stg branch --create' record parent information.

From
Yann Dirson <ydirson@altern.org>
Date
Jan 27, 2007, 17:22 UTC
Message-ID
<20070127172253.27183.28126.stgit@gandelf.nowhere.earth>
In-Reply-To
<20070127172129.27183.50432.stgit@gandelf.nowhere.earth>
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 stgit/commands/branch.py |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index d348409..f074d47 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -123,10 +123,41 @@ def func(parser, options, args):
         check_head_top_equal()
 
         tree_id = None
-        if len(args) == 2:
+        if len(args) >= 2:
+            try:
+                if git.rev_parse(args[1]) == git.rev_parse('refs/heads/' + args[1]):
+                    # we are for sure refering to a branch
+                    parentbranch = 'refs/heads/' + args[1]
+                    print 'Recording "%s" as parent branch.' % parentbranch
+                elif git.rev_parse(args[1]) and re.search('/', args[1]):
+                    # FIXME: should the test be more strict ?
+                    parentbranch = args[1]
+                else:
+                    # Note: this includes refs to StGIT patches
+                    print 'Don\'t know how to determine parent branch from "%s".' % args[1]
+                    parentbranch = None
+            except git.GitException:
+                # should use a more specific exception to catch only non-git refs ?
+                print 'Don\'t know how to determine parent branch from "%s".' % args[1]
+                parentbranch = None
+
             tree_id = git_id(args[1])
-        
-        stack.Series(args[0]).init(create_at = tree_id)
+        else:
+            # branch stack off current branch
+            parentbranch = git.get_head_file()
+
+        if parentbranch:
+            parentremote = git.identify_remote(parentbranch)
+            if parentremote:
+                print 'Using "%s" remote to pull parent from.' % parentremote
+            else:
+                print 'Not identified a remote to pull parent from.'
+        else:
+            parentremote = None
+
+        stack.Series(args[0]).init(create_at = tree_id,
+                                   parent_remote = parentremote,
+                                   parent_branch = parentbranch)
 
         print 'Branch "%s" created.' % args[0]
         return
Previous: Yann DirsonNext: Yann Dirson
Message 6 of 7 in “[DRAFT 2] StGIT, remotes, and parent information”
  1. 0/7 [DRAFT 2] StGIT, remotes, and parent informationYann Dirson, Jan 27, 2007
  2. 1/6 Make stgit.config use git-repo-config.Yann Dirson, Jan 27, 2007
  3. 2/6 Move identification of parent branch's remote def up into stack class.Yann Dirson, Jan 27, 2007
  4. 3/6 Allows extraction of information about remotes.Yann Dirson, Jan 27, 2007
  5. 4/6 Basic support for keeping a ref to the parent branch.Yann Dirson, Jan 27, 2007
  6. 5/6 Have 'stg branch --create' record parent information.Yann Dirson, Jan 27, 2007
  7. 6/6 Make 'stg pull' use git-fetch and not git-pull.Yann Dirson, Jan 27, 2007

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.