You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportOptionalfromgitimportRepo, GitCommandErrorfromflexlate.branch_updateimport (
get_flexlate_branch_name_for_feature_branch,
abort_merge_and_reset_flexlate_branches,
)
fromflexlate.cli_utilsimportconfirm_userfromflexlate.constantsimportDEFAULT_MERGED_BRANCH_NAME, DEFAULT_TEMPLATE_BRANCH_NAMEfromflexlate.ext_gitimport (
fast_forward_branch_without_checkout,
temp_repo_that_pushes_to_branch,
repo_has_merge_conflicts,
get_branch_sha,
delete_local_branch,
)
fromflexlate.stylesimport (
print_styled,
INFO_STYLE,
ACTION_REQUIRED_STYLE,
styled,
QUESTION_STYLE,
ALERT_STYLE,
SUCCESS_STYLE,
)
classMerger:
defmerge_flexlate_branches(
self,
repo: Repo,
branch_name: Optional[str] =None,
delete: bool=True,
merged_branch_name: str=DEFAULT_MERGED_BRANCH_NAME,
template_branch_name: str=DEFAULT_TEMPLATE_BRANCH_NAME,
):
feature_branch=branch_nameorrepo.active_branch.nameflexlate_feature_merged_branch_name= (
get_flexlate_branch_name_for_feature_branch(
feature_branch, merged_branch_name
)
)
flexlate_feature_template_branch_name= (
get_flexlate_branch_name_for_feature_branch(
feature_branch, template_branch_name
)
)
# Save the status of the flexlate branches. We may need to roll back to this state# if the user aborts the mergecurrent_branch=repo.active_branchmerged_branch_sha=get_branch_sha(repo, merged_branch_name)
template_branch_sha=get_branch_sha(repo, template_branch_name)
print_styled(
f"Merging {flexlate_feature_template_branch_name} to {template_branch_name}",
INFO_STYLE,
)
try:
fast_forward_branch_without_checkout(
repo, template_branch_name, flexlate_feature_template_branch_name
)
exceptGitCommandErrorase:
# TODO: make sure it's the right git error# Could not fast forward. Must do a merge in a temp repo and have user resolve any conflictswithtemp_repo_that_pushes_to_branch( # type: ignorerepo,
branch_name=template_branch_name,
base_branch_name=template_branch_name,
additional_branches=(flexlate_feature_template_branch_name,),
) astemp_repo:
temp_repo.git.merge(flexlate_feature_template_branch_name) # type: ignoreifrepo_has_merge_conflicts(temp_repo):
print_styled(
f"Encountered merge conflicts while merging "f"{flexlate_feature_template_branch_name} into {template_branch_name}",
INFO_STYLE,
)
print_styled(
f"Flexlate uses a temporary repo for this merge. "f"Please resolve conflicts in {temp_repo.working_dir}", # type: ignoreACTION_REQUIRED_STYLE,
)
handled_conflicts=confirm_user(
styled(
"Successfully handled conflicts? n to abort", QUESTION_STYLE
)
)
ifnothandled_conflicts:
# Have only done work in a temp dir so far, so can just abortprint_styled("Aborting merge.", ALERT_STYLE)
returnprint_styled(
f"Successfully merged {flexlate_feature_template_branch_name} to {template_branch_name}",
SUCCESS_STYLE,
)
# Now merge the merged branch in the main repotry:
fast_forward_branch_without_checkout(
repo, merged_branch_name, flexlate_feature_merged_branch_name
)
exceptGitCommandErrorase:
# TODO: make sure it's the right git error# Could not fast forward. Must do a merge and have user resolve any conflictsmerged_branch=repo.branches[merged_branch_name] # type: ignoremerged_branch.checkout()
repo.git.merge(flexlate_feature_merged_branch_name)
ifrepo_has_merge_conflicts(temp_repo):
print_styled(
f"Encountered merge conflicts while merging "f"{flexlate_feature_template_branch_name} into {template_branch_name}",
INFO_STYLE,
)
print_styled(f"Please resolve the conflicts", ACTION_REQUIRED_STYLE)
handled_conflicts=confirm_user(
styled("Successfully handled conflicts? n to abort", QUESTION_STYLE)
)
ifnothandled_conflicts:
# Time ot abort, but need to reset the state of the branchesprint_styled("Aborting merge.", ALERT_STYLE)
abort_merge_and_reset_flexlate_branches(
repo,
current_branch,
merged_branch_sha=merged_branch_sha,
template_branch_sha=template_branch_sha,
merged_branch_name=merged_branch_name,
template_branch_name=template_branch_name,
)
returnprint_styled(
f"Successfully merged {flexlate_feature_merged_branch_name} to {merged_branch_name}",
SUCCESS_STYLE,
)
ifnotdelete:
return# Handle deleteprint_styled(
f"Deleting flexlate feature branches {flexlate_feature_template_branch_name} and {flexlate_feature_merged_branch_name}",
INFO_STYLE,
)
delete_local_branch(repo, flexlate_feature_template_branch_name)
delete_local_branch(repo, flexlate_feature_merged_branch_name)
print_styled(f"Successfully deleted flexlate feature branches", SUCCESS_STYLE)
24464e762b46e19a1500c58243a696e37bfd6baa
The text was updated successfully, but these errors were encountered:
make sure it's the right git error
Could not fast forward. Must do a merge and have user resolve any conflicts
flexlate/flexlate/merger.py
Line 65 in 5aecde4
24464e762b46e19a1500c58243a696e37bfd6baa
The text was updated successfully, but these errors were encountered: