X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/bad9dcfc19eb88f866ebf97692fbde5d7827f76e..4f5a8c722ee88f9be891297353ae26f676bb0213:/stgit/commands/branch.py diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py index ef44349..f074d47 100644 --- a/stgit/commands/branch.py +++ b/stgit/commands/branch.py @@ -23,7 +23,7 @@ from optparse import OptionParser, make_option from stgit.commands.common import * from stgit.utils import * -from stgit import stack, git +from stgit import stack, git, basedir help = 'manage development branches' @@ -123,11 +123,41 @@ def func(parser, options, args): check_head_top_equal() tree_id = None - if len(args) == 2: - tree_id = args[1] + 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]) + 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 - git.create_branch(args[0], tree_id) - stack.Series(args[0]).init() + stack.Series(args[0]).init(create_at = tree_id, + parent_remote = parentremote, + parent_branch = parentbranch) print 'Branch "%s" created.' % args[0] return @@ -173,13 +203,19 @@ def func(parser, options, args): if len(args) != 0: parser.error('incorrect number of arguments') - branches = os.listdir(os.path.join(git.get_base_dir(), 'refs', 'heads')) + branches = [] + basepath = os.path.join(basedir.get(), 'refs', 'heads') + for path, files, dirs in walk_tree(basepath): + branches += [os.path.join(path, f) for f in files] branches.sort() - max_len = max([len(i) for i in branches]) - print 'Available branches:' - for i in branches: - __print_branch(i, max_len) + if branches: + print 'Available branches:' + max_len = max([len(i) for i in branches]) + for i in branches: + __print_branch(i, max_len) + else: + print 'No branches' return elif options.protect: