Esempio n. 1
0
def _ask_branch(args, name, desc1, desc2, suggestions, filter=[]):
    # Two cases are distinguished:
    # 1. A fresh git repo (without any branches)
    #    We will create a new master/develop branch for the user
    # 2. Some branches do already exist
    #    We will disallow creation of new master/develop branches and
    #    rather allow to use existing branches for git-flow.
    askingForStage = name is "stage"
    name = "gitflow.branch." + name
    default_name = gitflow.get_default(name)
    local_branches = [b for b in gitflow.branch_names() if b not in filter]
    if not local_branches:
        if not filter:
            print "No branches exist yet. Base branches must be created now."
        should_check_existence = False
        default_suggestion = default_name
    else:
        # Check unless we are picking up the stage branch.
        # That one is created automatically on deploy, it doesn't have to exist.
        should_check_existence = not askingForStage
        print
        print "Which branch should be used for %s?" % desc1
        for b in local_branches:
            print "  -", b
        for default_suggestion in [default_name] + suggestions:
            if default_suggestion in local_branches:
                break
        else:
            if askingForStage:
                # Show the default suggesting even though the local branch doesn't exist.
                # The stage branch is created automatically by GitFlow later.
                default_suggestion = default_name
            else:
                default_suggestion = ""

    if args.use_defaults and default_suggestion:
        print "Branch name for %s:" % desc2, default_suggestion
        branch_name = default_suggestion
    else:
        answer = raw_input("Branch name for %s: [%s] " % (desc2, default_suggestion))
        branch_name = answer.strip() or default_suggestion
    if not branch_name:
        raise SystemExit("You need to give a branch name.")
    # check existence in case of an already existing repo
    if branch_name in filter:
        raise SystemExit("Production and integration branches should differ.")
    if should_check_existence:
        # if no local branch exists and a remote branch of the same
        # name exists, checkout that branch and use it for the local branch
        if not branch_name in local_branches:
            remote_name = gitflow.origin_name(branch_name)
            if remote_name in gitflow.branch_names(remote=True):
                branch = gitflow.repo.create_head(branch_name, remote_name)
                info("Created local branch %s based on %s." % (branch_name, remote_name))
            else:
                raise NoSuchLocalBranchError(branch_name)

    # store the name of the develop branch
    gitflow.set(name, branch_name)
    return branch_name
Esempio n. 2
0
 def run(args):
     gitflow = GitFlow()
     for name, hexsha, is_active_branch in gitflow.status():
         if is_active_branch:
             prefix = '*'
         else:
             prefix = ' '
         info('%s %s: %s' % (prefix, name, hexsha[:7]))
Esempio n. 3
0
 def run(args):
     gitflow = GitFlow()
     for name, hexsha, is_active_branch in gitflow.status():
         if is_active_branch:
             prefix = '*'
         else:
             prefix = ' '
         info('%s %s: %s' % (prefix, name, hexsha[:7]))
Esempio n. 4
0
def _ask_branch(args, name, desc1, desc2, suggestions, filter=[]):
    # Two cases are distinguished:
    # 1. A fresh git repo (without any branches)
    #    We will create a new master/develop branch for the user
    # 2. Some branches do already exist
    #    We will disallow creation of new master/develop branches and
    #    rather allow to use existing branches for git-flow.
    name = 'gitflow.branch.' + name
    default_name = gitflow.get_default(name)
    local_branches = [b
                      for b in gitflow.branch_names()
                      if b not in filter]
    if not local_branches:
        if not filter:
            print("No branches exist yet. Base branches must be created now.")
        should_check_existence = False
        default_suggestion = default_name
    else:
        should_check_existence = True
        print("Which branch should be used for %s?" % desc1)
        for b in local_branches:
            print('  -', b)
        for default_suggestion in [default_name] + suggestions:
            if default_suggestion in local_branches:
                break
        else:
            default_suggestion = ''

    if args.use_defaults and default_suggestion:
        print("Branch name for %s:" % desc2, default_suggestion)
        branch_name = default_suggestion
    else:
        answer = input("Branch name for %s: [%s] "
                           % (desc2, default_suggestion))
        branch_name = answer.strip() or default_suggestion
    if not branch_name:
        raise SystemExit('You need to give a branch name.')
    # check existence in case of an already existing repo
    if branch_name in filter:
        raise SystemExit("Production and integration branches should differ.")
    if should_check_existence:
        # if no local branch exists and a remote branch of the same
        # name exists, checkout that branch and use it for the local branch
        if branch_name not in local_branches:
            remote_name = gitflow.origin_name(branch_name)
            if remote_name in gitflow.branch_names(remote=True):
                branch = gitflow.repo.create_head(branch_name, remote_name)
                info("Created local branch %s based on %s."
                     % (branch_name, remote_name))
            else:
                raise NoSuchLocalBranchError(branch_name)

    # store the name of the develop branch
    gitflow.set(name, branch_name)
    return branch_name
Esempio n. 5
0
def _ask_branch(args, name, desc1, desc2, suggestions, filter=[]):
    # Two cases are distinguished:
    # 1. A fresh git repo (without any branches)
    #    We will create a new master/develop branch for the user
    # 2. Some branches do already exist
    #    We will disallow creation of new master/develop branches and
    #    rather allow to use existing branches for git-flow.
    name = 'gitflow.branch.' + name
    default_name = gitflow.get_default(name)
    local_branches = [b for b in gitflow.branch_names() if b not in filter]
    if not local_branches:
        if not filter:
            print "No branches exist yet. Base branches must be created now."
        should_check_existence = False
        default_suggestion = default_name
    else:
        should_check_existence = True
        print
        print "Which branch should be used for %s?" % desc1
        for b in local_branches:
            print '  -', b
        for default_suggestion in [default_name] + suggestions:
            if default_suggestion in local_branches:
                break
        else:
            default_suggestion = ''

    if args.use_defaults and default_suggestion:
        print "Branch name for %s:" % desc2, default_suggestion
        branch_name = default_suggestion
    else:
        answer = raw_input("Branch name for %s: [%s] " %
                           (desc2, default_suggestion))
        branch_name = answer.strip() or default_suggestion
    if not branch_name:
        raise SystemExit('You need to give a branch name.')
    # check existence in case of an already existing repo
    if branch_name in filter:
        raise SystemExit("Production and integration branches should differ.")
    if should_check_existence:
        # if no local branch exists and a remote branch of the same
        # name exists, checkout that branch and use it for the local branch
        if not branch_name in local_branches:
            remote_name = gitflow.origin_name(branch_name)
            if remote_name in gitflow.branch_names(remote=True):
                branch = gitflow.repo.create_head(branch_name, remote_name)
                info("Created local branch %s based on %s." %
                     (branch_name, remote_name))
            else:
                raise NoSuchLocalBranchError(branch_name)

    # store the name of the develop branch
    gitflow.set(name, branch_name)
    return branch_name