git-mr-update: check that MR in in-reply-to header matches RM ref
authorFrantisek Hrbata <frantisek@hrbata.com>
Wed, 16 Dec 2020 11:11:35 +0000 (12:11 +0100)
committerFrantisek Hrbata <frantisek@hrbata.com>
Wed, 16 Dec 2020 11:11:35 +0000 (12:11 +0100)
Signed-off-by: Frantisek Hrbata <frantisek@hrbata.com>
git-mr-update

index 9b8a06d5adb2feacedf50c26158deb576f8eb171..0bedda1d0caf6ab54a6f8dd62aa67f18d870f46d 100755 (executable)
@@ -171,6 +171,8 @@ elif ref_type == "mbox":
             continue
         revs.append(line)
 
+    mr_re = re.compile("<([0-9a-f]{40})")
+
     for rev in revs:
         rv, out, err = mrlib.run(["git", "show", "--format=%b", rev])
         lines = out.split("\n")
@@ -183,6 +185,13 @@ elif ref_type == "mbox":
         if not lines[1].lower().startswith("in-reply-to: "):
             sys.exit("Expecting 2nd line '{}' to be 'In-Reply-To' header.".format(lines[1]))
 
+        match = mr_re.match(lines[1].split()[1])
+        if not match:
+            sys.exit("Cannot find MR in '{}'.".format(lines[1]))
+
+        if match[1] != ref_mr:
+            sys.exit("MR '{}' in In-Reply-To header does not match '{}'.".format(match[1], ref_mr))
+
         if lines[2]:
             sys.exit("Expecting 3rd line '{}' to be empty.".format(lines[2]))