From 28ebf108a95384daecd043a9d714974d3e17b5dc Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 19 Feb 2013 13:17:48 -0500 Subject: [PATCH] git integration: Fix handling of new/removed branches. (imported from commit f87ba78dbc292a05d82aedc74a90de6cbefee3e2) --- integrations/git/post-receive | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/integrations/git/post-receive b/integrations/git/post-receive index 6d8ecb6..3c07057 100755 --- a/integrations/git/post-receive +++ b/integrations/git/post-receive @@ -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