From 5f8041552bc6e5c0df7012420d576929dacb2a4e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 18 Oct 2019 11:21:52 +0200 Subject: [PATCH] [FIX] forwardport: apparently git/refs/heads can fuzzy-match If the ref we asked for does not exist, github apparently decides to fall-back to prefix-matching. So if we're trying to delete already-deleted branch A and someone called their branch A-x we're going to get it as a result. Thankfully they were apparently smart enough to return a list even if there's only a single fuzzy match. So if we get a list (instead of a dict) as response to git/refs/heads assume the branch was already deleted as if we got a 404. --- forwardport/models/forwardport.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/forwardport/models/forwardport.py b/forwardport/models/forwardport.py index 9df559c6..86b8d841 100644 --- a/forwardport/models/forwardport.py +++ b/forwardport/models/forwardport.py @@ -140,6 +140,12 @@ class DeleteBranches(models.Model, Queue): return ref = ref.json() + if isinstance(ref, list): + _deleter.info( + "✘ got a fuzzy match (%s), branch probably deleted", + ', '.join(r['ref'] for r in ref) + ) + if ref['object']['sha'] != self.pr_id.head: _deleter.info( "✘ branch %s head mismatch, expected %s, got %s",