summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2016-08-08 15:38:43 +0100
committerThibault Saunier <tsaunier@gnome.org>2016-08-09 14:37:36 -0400
commite0cbfcf63097f49ade53b9e1078a54fecc19fbc0 (patch)
treee87bd7f56bf8b4034eb4ac2032fbe388e0b6d2b0
parentd37add1b2fa5118163ed003ae6d575e69bcc95fb (diff)
git-phab: Fix inclusion of git fields in attach commit messages
The move away from arc broke inclusion of git fields (such as Signed-off-by or Reviewed-by) in commit messages when using `git phab attach` to upload them to Phabricator. Fix that by handling git and Phabricator fields separately, and more explicitly. Signed-off-by: Philip Withnall <philip.withnall@collabora.co.uk> Reviewed-by: Thibault Saunier <tsaunier@gnome.org> Differential Revision: https://phabricator.freedesktop.org/D1252
-rwxr-xr-xgit-phab37
1 files changed, 20 insertions, 17 deletions
diff --git a/git-phab b/git-phab
index d693842..8d9b103 100755
--- a/git-phab
+++ b/git-phab
@@ -629,7 +629,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
629 629
630 body.append(line) 630 body.append(line)
631 631
632 return subject, body, git_fields + phab_fields, updates 632 return subject, body, git_fields, phab_fields, updates
633 633
634 def strip_updates(self, msg): 634 def strip_updates(self, msg):
635 """ 635 """
@@ -649,7 +649,8 @@ 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, fields, ask=False): 652 def format_commit_msg(self, subject, body, git_fields, phab_fields,
653 ask=False):
653 # This is the list of fields phabricator will search by default in 654 # This is the list of fields phabricator will search by default in
654 # commit message, case insensitive. It will confuse phabricator's 655 # commit message, case insensitive. It will confuse phabricator's
655 # parser if they appear in the subject or body of the commit message. 656 # parser if they appear in the subject or body of the commit message.
@@ -663,7 +664,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
663 664
664 subject = subject.strip() 665 subject = subject.strip()
665 body = '\n'.join(body).strip() 666 body = '\n'.join(body).strip()
666 fields = '\n'.join(fields).strip() 667 fields = '\n'.join(git_fields + phab_fields).strip()
667 668
668 for header in blacklist: 669 for header in blacklist:
669 header_ = header[:-1] + '_:' 670 header_ = header[:-1] + '_:'
@@ -970,7 +971,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
970 971
971 diff = self.create_diff(commit, linter_status) 972 diff = self.create_diff(commit, linter_status)
972 phab = self.phabricator 973 phab = self.phabricator
973 subject, body, fields, updates = self.parse_commit_msg(commit.message) 974 subject, body, git_fields, phab_fields, updates = \
975 self.parse_commit_msg(commit.message)
974 976
975 try: 977 try:
976 last_revision_id = self.get_differential_id( 978 last_revision_id = self.get_differential_id(
@@ -981,24 +983,26 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
981 if last_revision_id: 983 if last_revision_id:
982 body.append("Depends on D%s" % last_revision_id) 984 body.append("Depends on D%s" % last_revision_id)
983 985
984 fields.append("Projects: %s" % ','.join(self.project_phids)) 986 phab_fields.append("Projects: %s" % ','.join(self.project_phids))
987
988 summary = ('\n'.join(body) + '\n' + '\n'.join(git_fields)).strip()
985 989
986 revision_id = self.get_differential_id(self.repo.head.commit) 990 revision_id = self.get_differential_id(self.repo.head.commit)
987 if revision_id: 991 if revision_id:
988 arc_message = phab.differential.getcommitmessage( 992 arc_message = phab.differential.getcommitmessage(
989 revision_id=revision_id, edit="update", 993 revision_id=revision_id, edit="update",
990 fields=fields).response 994 fields=phab_fields).response
991 else: 995 else:
992 arc_message = phab.differential.getcommitmessage( 996 arc_message = phab.differential.getcommitmessage(
993 edit="create", fields=fields).response 997 edit="create", fields=phab_fields).response
994 998
995 arc_message = arc_message.replace( 999 arc_message = arc_message.replace(
996 "<<Replace this line with your Revision Title>>", 1000 "<<Replace this line with your Revision Title>>",
997 subject) 1001 subject)
998 if body: 1002 if summary != '':
999 arc_message = arc_message.replace( 1003 arc_message = arc_message.replace(
1000 "Summary: ", 1004 "Summary: ",
1001 "Summary:\n" + '\n'.join(body)) 1005 "Summary:\n" + summary)
1002 1006
1003 if self.reviewers: 1007 if self.reviewers:
1004 arc_message = arc_message.replace( 1008 arc_message = arc_message.replace(
@@ -1043,7 +1047,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1043 subject) 1047 subject)
1044 message = "\n".join(message) 1048 message = "\n".join(message)
1045 1049
1046 fields["summary"] = '\n'.join(body) 1050 fields["summary"] = summary
1047 fields["title"] = subject 1051 fields["title"] = subject
1048 if linter_message: 1052 if linter_message:
1049 message += "\n\n%s" % linter_message 1053 message += "\n\n%s" % linter_message
@@ -1701,17 +1705,16 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1701 # - Ensure body doesn't contain blacklisted words 1705 # - Ensure body doesn't contain blacklisted words
1702 # - Ensure phabricator fields are last to make its parser happy 1706 # - Ensure phabricator fields are last to make its parser happy
1703 # - Discard updates/discussion of previous patch revisions 1707 # - Discard updates/discussion of previous patch revisions
1704 subject, body, fields, updates = self.parse_commit_msg( 1708 subject, body, git_fields, phab_fields, updates = \
1705 self.repo.head.commit.message) 1709 self.parse_commit_msg(self.repo.head.commit.message)
1706 1710
1707 for r in reviewers: 1711 for r in reviewers:
1708 # Note that we prepend here to make sur phab fields
1709 # stay last.
1710 field = "Reviewed-by: " + r 1712 field = "Reviewed-by: " + r
1711 if field not in fields: 1713 if field not in git_fields:
1712 fields.insert(0, field) 1714 git_fields.append(field)
1713 1715
1714 msg = self.format_commit_msg(subject, body, fields, True) 1716 msg = self.format_commit_msg(subject, body, git_fields,
1717 phab_fields, True)
1715 self.repo.git.commit(amend=True, message=msg) 1718 self.repo.git.commit(amend=True, message=msg)
1716 1719
1717 orig_branch.commit = self.repo.head.commit 1720 orig_branch.commit = self.repo.head.commit