+ if len(args) >= 2:
+ parentbranch = None
+ try:
+ branchpoint = git.rev_parse(args[1])
+
+ # parent branch?
+ head_re = re.compile('refs/(heads|remotes)/')
+ ref_re = re.compile(args[1] + '$')
+ for ref in git.all_refs():
+ if head_re.match(ref) and ref_re.search(ref):
+ # args[1] is a valid ref from the branchpoint
+ # setting above
+ parentbranch = args[1]
+ break;
+ except git.GitException:
+ # should use a more specific exception to catch only
+ # non-git refs ?
+ out.info('Don\'t know how to determine parent branch'
+ ' from "%s"' % args[1])
+ # exception in branch = rev_parse() leaves branchpoint unbound
+ branchpoint = None
+
+ tree_id = git_id(crt_series, branchpoint or args[1])
+
+ if parentbranch:
+ out.info('Recording "%s" as parent branch' % parentbranch)
+ else:
+ out.info('Don\'t know how to determine parent branch'
+ ' from "%s"' % args[1])
+ else:
+ # branch stack off current branch
+ parentbranch = git.get_head_file()
+
+ if parentbranch:
+ parentremote = git.identify_remote(parentbranch)
+ if parentremote:
+ out.info('Using remote "%s" to pull parent from'
+ % parentremote)
+ else:
+ out.info('Recording as a local branch')
+ else:
+ # no known parent branch, can't guess the remote
+ parentremote = None
+
+ stack.Series(args[0]).init(create_at = tree_id,
+ parent_remote = parentremote,
+ parent_branch = parentbranch)