Skip to content

Commit

Permalink
Merge pull request frostming#173 from wkentaro/unpublish-fail-msg
Browse files Browse the repository at this point in the history
Fetch and abort if unpublishing branch not found
  • Loading branch information
hickford committed Aug 24, 2015
2 parents 5cf5121 + 5569e7e commit 479c036
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 7 additions & 3 deletions legit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,14 @@ def display_version():
))


def handle_abort(aborted):
print(colored.red('Error:'), aborted.message)
def handle_abort(aborted, type=None):
print('{0} {1}'.format(colored.red('Error:'), aborted.message))
print(black(str(aborted.log)))
print('Unfortunately, there was a merge conflict. It has to be merged manually.')
if type == 'merge':
print('Unfortunately, there was a merge conflict.'
' It has to be merged manually.')
elif type == 'unpublish':
print('It seems that the remote branch has been already deleted.')
sys.exit(1)


Expand Down
19 changes: 13 additions & 6 deletions legit/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def __init__(self):
self.log = None


def abort(message, log=None):
def abort(message, log=None, type=None):

a = Aborted()
a.message = message
a.log = log

settings.abort_handler(a)
settings.abort_handler(a, type=type)

def repo_check(require_remote=False):
if repo is None:
Expand Down Expand Up @@ -138,7 +138,8 @@ def smart_merge(branch, allow_rebase=True):
return repo.git.execute([git, verb, branch])
except GitCommandError as why:
log = repo.git.execute([git, verb, '--abort'])
abort('Merge failed. Reverting.', log='{0}\n{1}'.format(why, log))
abort('Merge failed. Reverting.',
log='{0}\n{1}'.format(why, log), type='merge')



Expand Down Expand Up @@ -180,7 +181,8 @@ def graft_branch(branch):
log.append(msg)
except GitCommandError as why:
log = repo.git.execute([git,'merge', '--abort'])
abort('Merge failed. Reverting.', log='{0}\n{1}'.format(why, log))
abort('Merge failed. Reverting.',
log='{0}\n{1}'.format(why, log), type='merge')


out = repo.git.execute([git, 'branch', '-D', branch])
Expand All @@ -193,8 +195,13 @@ def unpublish_branch(branch):

repo_check()

return repo.git.execute([git,
'push', remote.name, ':{0}'.format(branch)])
try:
return repo.git.execute([git,
'push', remote.name, ':{0}'.format(branch)])
except GitCommandError:
_, _, log = repo.git.execute([git, 'fetch', remote.name, '--prune'],
with_extended_output=True)
abort('Unpublish failed. Fetching.', log=log, type='unpublish')


def publish_branch(branch):
Expand Down

0 comments on commit 479c036

Please sign in to comment.