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

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 36ead9f9c862b7bbae2435b26be6c01ea83e4f34
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/turnip:bug-1878669
Merge into: turnip:master
Diff against target: 47 lines (+20/-3)
2 files modified
turnip/pack/hooks/hook.py (+7/-3)
turnip/pack/tests/test_hooks.py (+13/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+384249@code.launchpad.net

Commit message

Don't send MP URL for branch deletion.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/pack/hooks/hook.py b/turnip/pack/hooks/hook.py
2index 61740c4..e135395 100755
3--- a/turnip/pack/hooks/hook.py
4+++ b/turnip/pack/hooks/hook.py
5@@ -146,11 +146,15 @@ def check_ref_permissions(sock, rpc_key, ref_paths):
6
7
8 def send_mp_url(received_line):
9- ref = received_line.rstrip(b'\n').split(b' ', 2)[2]
10+ _, new_sha, ref = received_line.rstrip(b'\n').split(b' ', 2)
11
12- # check for branch ref here (we're interested in
13- # heads and not tags)
14+ # The new sha will be zero when deleting branch
15+ # in which case we do not want to send the MP URL.
16+ if new_sha == GIT_OID_HEX_ZERO:
17+ return
18
19+ # Check for branch ref here - we're interested in
20+ # heads and not tags.
21 if ref.startswith(b'refs/heads/') and not is_default_branch(ref):
22 pushed_branch = ref[len(b'refs/heads/'):]
23 if not is_default_branch(pushed_branch):
24diff --git a/turnip/pack/tests/test_hooks.py b/turnip/pack/tests/test_hooks.py
25index cc785d8..449b9f9 100644
26--- a/turnip/pack/tests/test_hooks.py
27+++ b/turnip/pack/tests/test_hooks.py
28@@ -306,6 +306,19 @@ class TestPostReceiveHook(HookTestMixin, TestCase):
29 finally:
30 os.chdir(curdir)
31
32+ @defer.inlineCallbacks
33+ def test_no_merge_proposal_URL_delete_branch(self):
34+ # No MP URL received for delete of non default branch
35+ curdir = os.getcwd()
36+ try:
37+ os.chdir(self.repo_dir)
38+ yield self.assertAccepted([(
39+ b'pushed_branch',
40+ self.old_sha1, pygit2.GIT_OID_HEX_ZERO)],
41+ {b'pushed_branch': ['force_push']})
42+ finally:
43+ os.chdir(curdir)
44+
45
46 class TestUpdateHook(TestCase):
47 """Tests for the git update hook"""

Subscribers

People subscribed via source and target branches