Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/better-merge-conflict-error-msg'
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Oct 13, 2016
2 parents 065ef79 + e26b0a5 commit 5a8323c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions badwolf/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ def _merge_pull_request(self, gitcmd):
gitcmd.fetch(target_remote, target_branch)
gitcmd.checkout('FETCH_HEAD')
gitcmd.merge('origin/{}'.format(self.context.source['branch']['name']))

@staticmethod
def get_conflicted_files(repo_path):
gitcmd = git.Git(repo_path)
try:
return gitcmd.diff('--name-only', '--diff-filter=U')
except git.GitCommandError:
logger.exception('Error get conflicted files by git diff command')
return None
12 changes: 11 additions & 1 deletion badwolf/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ def start(self):

def _report_git_error(self, exc):
self.build_status.update('FAILED', description='Git clone repository failed')
content = ':broken_heart: **Git error**: {}'.format(to_text(exc))
git_error_msg = to_text(exc)
content = ':broken_heart: **Git error**: {}'.format(git_error_msg)
if 'Merge conflict' in git_error_msg:
# git merge conflicted
conflicted_files = RepositoryCloner.get_conflicted_files(
self.context.clone_path
)
if conflicted_files:
conflicted_files = '\n'.join(('* ' + name for name in conflicted_files.split('\n')))
content = ':broken_heart: This branch has conflicts that must be resolved\n\n'
content += '**Conflicting files**\n\n{}'.format(conflicted_files)
content = sanitize_sensitive_data(content)
if self.context.pr_id:
pr = PullRequest(bitbucket, self.context.repository)
Expand Down

0 comments on commit 5a8323c

Please sign in to comment.