|
|
@@ -17,16 +17,15 @@ class MergeCommand(Command):
|
|
|
|
|
|
|
|
|
|
|
|
branch = self.ensure_right_branch()
|
|
|
|
branch = self.ensure_right_branch()
|
|
|
|
(target, _) = self.get_branch_env_and_type(branch)
|
|
|
|
(target, _) = self.get_branch_env_and_type(branch)
|
|
|
|
base = Git.get_first_fork_point(branch, target)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if "flow.remote" in self.flowconfig:
|
|
|
|
if "flow.remote" in self.flowconfig:
|
|
|
|
remote = self.flowconfig["flow.remote"]
|
|
|
|
remote = self.flowconfig["flow.remote"]
|
|
|
|
token = self.ensure_repository_token()
|
|
|
|
token = self.ensure_repository_token()
|
|
|
|
self.run_remote(remote, token, base, branch, target)
|
|
|
|
self.run_remote(remote, token, branch, target)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.run_local(base, branch, target)
|
|
|
|
self.run_local(branch, target)
|
|
|
|
|
|
|
|
|
|
|
|
def run_remote(self, remote: str, token: str, base: str, branch: str, target: str):
|
|
|
|
def run_remote(self, remote: str, token: str, branch: str, target: str):
|
|
|
|
self.ensure_clean_worktree(True)
|
|
|
|
self.ensure_clean_worktree(True)
|
|
|
|
|
|
|
|
|
|
|
|
Git("switch", target).exec(print="Cambiando a rama destino")
|
|
|
|
Git("switch", target).exec(print="Cambiando a rama destino")
|
|
|
@@ -34,26 +33,26 @@ class MergeCommand(Command):
|
|
|
|
Git("switch", "-").exec(print="Volviendo a rama a mergear")
|
|
|
|
Git("switch", "-").exec(print="Volviendo a rama a mergear")
|
|
|
|
|
|
|
|
|
|
|
|
self.check_merge_conflicts(target)
|
|
|
|
self.check_merge_conflicts(target)
|
|
|
|
self.show_commits_to_merge(base)
|
|
|
|
self.show_commits_to_merge(target)
|
|
|
|
|
|
|
|
|
|
|
|
if self.confirm(f"¿Crear PR de '{branch}' a '{target}'?"):
|
|
|
|
if self.confirm(f"¿Crear PR de '{branch}' a '{target}'?"):
|
|
|
|
Git("push", remote, branch, set_upstream=True).exec(
|
|
|
|
Git("push", remote, branch, set_upstream=True).exec(
|
|
|
|
print="Subiendo rama al remoto para crear PR"
|
|
|
|
print="Subiendo rama al remoto para crear PR"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
self.create_pull_request(token, base, branch, target)
|
|
|
|
self.create_pull_request(token, branch, target)
|
|
|
|
|
|
|
|
|
|
|
|
def run_local(self, base: str, branch: str, target: str):
|
|
|
|
def run_local(self, branch: str, target: str):
|
|
|
|
self.ensure_clean_worktree(False)
|
|
|
|
self.ensure_clean_worktree(False)
|
|
|
|
self.check_merge_conflicts(target)
|
|
|
|
self.check_merge_conflicts(target)
|
|
|
|
self.show_commits_to_merge(base)
|
|
|
|
self.show_commits_to_merge(target)
|
|
|
|
|
|
|
|
|
|
|
|
if self.confirm(f"¿Mergear rama '{branch}' a '{target}'?"):
|
|
|
|
if self.confirm(f"¿Mergear rama '{branch}' a '{target}'?"):
|
|
|
|
Git("switch", target).exec(print="Cambiando a rama destino")
|
|
|
|
Git("switch", target).exec(print="Cambiando a rama destino")
|
|
|
|
Git("merge", branch, ff=False).exec(print="Mergeando")
|
|
|
|
Git("merge", branch, ff=False).exec(print="Mergeando")
|
|
|
|
|
|
|
|
|
|
|
|
def show_commits_to_merge(self, base):
|
|
|
|
def show_commits_to_merge(self, target):
|
|
|
|
commits = Git("log", base + "..", format="%s").lines()
|
|
|
|
commits = Git("log", target + "..", format="%s").lines()
|
|
|
|
|
|
|
|
|
|
|
|
if not commits:
|
|
|
|
if not commits:
|
|
|
|
raise GitFlowError("No hay cambios a mergear.")
|
|
|
|
raise GitFlowError("No hay cambios a mergear.")
|
|
|
@@ -79,14 +78,14 @@ class MergeCommand(Command):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.success("No se detectaron merge conflicts.")
|
|
|
|
self.success("No se detectaron merge conflicts.")
|
|
|
|
|
|
|
|
|
|
|
|
def create_pull_request(self, token: str, base: str, branch: str, target: str):
|
|
|
|
def create_pull_request(self, token: str, branch: str, target: str):
|
|
|
|
changelog = Changelog()
|
|
|
|
changelog = Changelog()
|
|
|
|
|
|
|
|
|
|
|
|
message = self.get_remote_api(token).create_pull_request(
|
|
|
|
message = self.get_remote_api(token).create_pull_request(
|
|
|
|
branch,
|
|
|
|
branch,
|
|
|
|
target,
|
|
|
|
target,
|
|
|
|
branch.replace("/", ": ").replace("-", " "),
|
|
|
|
branch.replace("/", ": ").replace("-", " "),
|
|
|
|
changelog.generate_content(base, branch),
|
|
|
|
changelog.generate_content(target, branch),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
self.success(message)
|
|
|
|
self.success(message)
|
|
|
|