in ebcli/controllers/initialize.py [0:0]
def get_branch_interactive(repository):
source_control = SourceControl.get_source_control()
# Give list of code commit branches to use
new_branch = False
branch_list = codecommit.list_branches(repository)["branches"]
current_branch = source_control.get_current_branch()
# If there are existing branches prompt the user to pick one
if len(branch_list) > 0:
io.echo('Select a branch')
new_branch_option = '[ Create new Branch with local HEAD ]'
branch_list.append(new_branch_option)
try:
default_option = branch_list.index(current_branch) + 1
except ValueError:
default_option = len(branch_list)
branch_name = utils.prompt_for_item_in_list(branch_list,
default=default_option)
if branch_name == new_branch_option:
new_branch = True
# Create a new branch if the user specifies or there are no existing branches
if len(branch_list) == 0 or new_branch:
new_branch = True
io.echo()
io.echo('Enter Branch Name')
io.echo('***** Must have at least one commit to create a new branch with CodeCommit *****')
unique_name = utils.get_unique_name(current_branch, branch_list)
branch_name = io.prompt_for_unique_name(unique_name, branch_list)
# Setup git to push to this repo
result = codecommit.get_repository(repository)
remote_url = result['repositoryMetadata']['cloneUrlHttp']
source_control.setup_codecommit_remote_repo(remote_url=remote_url)
if len(branch_list) == 0 or new_branch:
LOG.debug("Creating a new branch")
try:
create_codecommit_branch(source_control, branch_name)
except ServiceError:
io.echo("Could not set CodeCommit branch with the current commit, run with '--debug' to get the full error")
return None
elif not new_branch:
LOG.debug("Setting up an existing branch")
succesful_branch = source_control.setup_existing_codecommit_branch(branch_name)
if not succesful_branch:
io.echo("Could not set CodeCommit branch, run with '--debug' to get the full error")
return None
return branch_name