+ if len(args) >= 2:
+ parentbranch = None
+ try:
+ branchpoint = git.rev_parse(args[1])
+
+ # first, look for branchpoint in well-known branch namespaces
+ for namespace in ('refs/heads/', 'remotes/'):
+ # check if branchpoint exists in namespace
+ try:
+ maybehead = git.rev_parse(namespace + args[1])
+ except git.GitException:
+ maybehead = None
+
+ # check if git resolved branchpoint to this namespace
+ if maybehead and branchpoint == maybehead:
+ # we are for sure referring to a branch
+ parentbranch = namespace + args[1]
+
+ 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)
+
+ out.info('Branch "%s" created' % args[0])
+ return
+
+ elif options.clone:
+
+ if len(args) == 0:
+ clone = crt_series.get_name() + \
+ 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(crt_series)