git integration: Fix handling of new/removed branches.

(imported from commit f87ba78dbc292a05d82aedc74a90de6cbefee3e2)
This commit is contained in:
Tim Abbott 2013-02-19 13:17:48 -05:00
parent a89b129781
commit c73ec65a2f
1 changed files with 15 additions and 4 deletions

View File

@ -88,12 +88,23 @@ def send_bot_message(oldrev, newrev, refname):
# Don't forward the notice anywhere
return
added = git_commit_range(oldrev, newrev)
removed = git_commit_range(newrev, oldrev)
new_head = newrev[:12]
old_head = oldrev[:12]
if removed:
if (oldrev == '0000000000000000000000000000000000000000' or
newrev == '0000000000000000000000000000000000000000'):
# New branch pushed or old branch removed
added = ''
removed = ''
else:
added = git_commit_range(oldrev, newrev)
removed = git_commit_range(newrev, oldrev)
if oldrev == '0000000000000000000000000000000000000000':
message = '`%s` was pushed to new branch `%s`' % (new_head, branch)
elif newrev == '0000000000000000000000000000000000000000':
message = 'branch `%s` was removed (was `%s`)' % (branch, old_head)
elif removed:
message = '`%s` was pushed to `%s`, **REMOVING**:\n\n%s' % (new_head, branch, removed)
if added:
message += '\n**and adding**:\n\n' + added