← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/turnip:bug-1878669 into turnip:master

 

Ioana Lasc has proposed merging ~ilasc/turnip:bug-1878669 into turnip:master.

Commit message:
Don't send MP URL for branch deletion.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ilasc/turnip/+git/turnip/+merge/384249

Proposed fix for bug-1878669.
For deleted branches the new sha will be received in the post-receive hook with all zeros. 
In this case we do not send the MP URL.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/turnip:bug-1878669 into turnip:master.
diff --git a/turnip/pack/hooks/hook.py b/turnip/pack/hooks/hook.py
index 61740c4..c577587 100755
--- a/turnip/pack/hooks/hook.py
+++ b/turnip/pack/hooks/hook.py
@@ -146,6 +146,13 @@ def check_ref_permissions(sock, rpc_key, ref_paths):
 
 
 def send_mp_url(received_line):
+
+    # the new sha will be zero for delete branch
+    # in this case we do not want to send the MP URL
+    new_sha = received_line.rstrip(b'\n').split(b' ', 2)[1]
+    if new_sha == GIT_OID_HEX_ZERO:
+        return
+            
     ref = received_line.rstrip(b'\n').split(b' ', 2)[2]
 
     # check for branch ref here (we're interested in
diff --git a/turnip/pack/tests/test_hooks.py b/turnip/pack/tests/test_hooks.py
index cc785d8..051c557 100644
--- a/turnip/pack/tests/test_hooks.py
+++ b/turnip/pack/tests/test_hooks.py
@@ -137,7 +137,8 @@ class HookTestMixin(object):
 
     old_sha1 = b'a' * 40
     new_sha1 = b'b' * 40
-
+    zero_sha = b'0' * 40
+    
     def handlePushNotification(self, path):
         self.notifications.append(path)
 
@@ -306,6 +307,22 @@ class TestPostReceiveHook(HookTestMixin, TestCase):
         finally:
             os.chdir(curdir)
 
+    @defer.inlineCallbacks
+    def test_no_merge_proposal_URL_delete_branch(self):
+        # No MP URL received for delete of non default branch
+        curdir = os.getcwd()
+        try:
+            os.chdir(self.repo_dir)
+            default_branch = subprocess.check_output(
+                ['git', 'symbolic-ref', 'HEAD']
+                ).rstrip(b'\n')
+            pushed_branch = str(default_branch + 'notdefault')
+            yield self.assertAccepted([(
+                b'%s' % pushed_branch,
+                self.old_sha1, self.zero_sha)],
+                {b'%s' % pushed_branch: ['push']})
+        finally:
+            os.chdir(curdir)
 
 class TestUpdateHook(TestCase):
     """Tests for the git update hook"""