summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2016-08-08 16:48:32 +0100
committerThibault Saunier <tsaunier@gnome.org>2016-08-09 14:37:39 -0400
commit80f3b4c34f442d737c376f18a15b9388dcbb3aed (patch)
treede1f54d59a66f71e5b5114bff61e2728c707e297
parente0cbfcf63097f49ade53b9e1078a54fecc19fbc0 (diff)
git-phab: Search for blacklisted fields in attach commit messages
As well as when landing a commit, search for blacklisted fields when initially attaching the commit to Phabricator, otherwise attaching a comment with a subject like ‘tests: Add more tests’ will fail. Signed-off-by: Philip Withnall <philip.withnall@collabora.co.uk> Reviewed-by: Thibault Saunier <tsaunier@gnome.org> Differential Revision: https://phabricator.freedesktop.org/D1255
-rwxr-xr-xgit-phab34
1 files changed, 19 insertions, 15 deletions
diff --git a/git-phab b/git-phab
index 8d9b103..6774541 100755
--- a/git-phab
+++ b/git-phab
@@ -649,8 +649,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
649 """ 649 """
650 return msg.split('\n---\n', 1)[0] 650 return msg.split('\n---\n', 1)[0]
651 651
652 def format_commit_msg(self, subject, body, git_fields, phab_fields, 652 def format_field(self, field, ask=False):
653 ask=False):
654 # This is the list of fields phabricator will search by default in 653 # This is the list of fields phabricator will search by default in
655 # commit message, case insensitive. It will confuse phabricator's 654 # commit message, case insensitive. It will confuse phabricator's
656 # parser if they appear in the subject or body of the commit message. 655 # parser if they appear in the subject or body of the commit message.
@@ -662,22 +661,27 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
662 'differential revision:', 'conflicts:', 'git-svn-id:', 661 'differential revision:', 'conflicts:', 'git-svn-id:',
663 'auditors:'] 662 'auditors:']
664 663
665 subject = subject.strip()
666 body = '\n'.join(body).strip()
667 fields = '\n'.join(git_fields + phab_fields).strip()
668
669 for header in blacklist: 664 for header in blacklist:
670 header_ = header[:-1] + '_:' 665 header_ = header[:-1] + '_:'
671 s = re.sub(re.escape(header), header_, subject, flags=re.I) 666 f = re.sub(re.escape(header), header_, field, flags=re.I)
672 b = re.sub(re.escape(header), header_, body, flags=re.I) 667 if (f != field) and (
673 if (s != subject or b != body) and (
674 not ask or self.prompt( 668 not ask or self.prompt(
675 "Commit message contains '%s'.\n" 669 "Commit message contains '%s'.\n"
676 "It could confuse phabricator's parser.\n" 670 "It could confuse Phabricator's parser.\n"
677 "Do you want to prefix is with an underscore?" % 671 "Do you want to suffix it with an underscore?" %
678 header)): 672 header)):
679 subject = s 673 field = f
680 body = b 674
675 return field
676
677 def format_commit_msg(self, subject, body, git_fields, phab_fields,
678 ask=False):
679 subject = subject.strip()
680 body = '\n'.join(body).strip()
681 fields = '\n'.join(git_fields + phab_fields).strip()
682
683 subject = self.format_field(subject, ask)
684 body = self.format_field(body, ask)
681 685
682 return '\n\n'.join([subject, body, fields]) 686 return '\n\n'.join([subject, body, fields])
683 687
@@ -998,11 +1002,11 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
998 1002
999 arc_message = arc_message.replace( 1003 arc_message = arc_message.replace(
1000 "<<Replace this line with your Revision Title>>", 1004 "<<Replace this line with your Revision Title>>",
1001 subject) 1005 self.format_field(subject, True))
1002 if summary != '': 1006 if summary != '':
1003 arc_message = arc_message.replace( 1007 arc_message = arc_message.replace(
1004 "Summary: ", 1008 "Summary: ",
1005 "Summary:\n" + summary) 1009 "Summary:\n" + self.format_field(summary, True))
1006 1010
1007 if self.reviewers: 1011 if self.reviewers:
1008 arc_message = arc_message.replace( 1012 arc_message = arc_message.replace(