summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-phab108
1 files changed, 76 insertions, 32 deletions
diff --git a/git-phab b/git-phab
index c2bd3e4..756a1ee 100755
--- a/git-phab
+++ b/git-phab
@@ -391,7 +391,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
391 return name 391 return name
392 392
393 def get_wip_branch(self): 393 def get_wip_branch(self):
394 return "wip/phab/" + self.branch_name_with_task() 394 return "devs/thisisbroken/" + self.branch_name_with_task()
395 395
396 def filter_already_proposed_commits(self, commits, all_commits): 396 def filter_already_proposed_commits(self, commits, all_commits):
397 if not self.task or not self.remote: 397 if not self.task or not self.remote:
@@ -495,12 +495,13 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
495 if not reply.data: 495 if not reply.data:
496 continue 496 continue
497 for (phid, data) in reply.data.items(): 497 for (phid, data) in reply.data.items():
498 project_map[data["name"].lower()] = phid 498 project_map[data["name"].lower()] = data["slugs"][0]
499 for s in data["slugs"]: 499 for s in data["slugs"]:
500 project_map[s.lower()] = phid 500 project_map[s.lower()] = s
501 501
502 try: 502 try:
503 for p in self.projects: 503 for p in self.projects:
504 p = p.lower()
504 if p not in project_map: 505 if p not in project_map:
505 print("%sProject `%s` doesn't seem to exist%s" % 506 print("%sProject `%s` doesn't seem to exist%s" %
506 (Colors.FAIL, p, Colors.ENDC)) 507 (Colors.FAIL, p, Colors.ENDC))
@@ -620,17 +621,20 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
620 if not self.reviewers: 621 if not self.reviewers:
621 self.reviewers = self.arcconfig.get("default-reviewers") 622 self.reviewers = self.arcconfig.get("default-reviewers")
622 623
623 self.projects = self.projects.split(',') if self.projects else [] 624 if self.projects:
624 if "project" in self.arcconfig: 625 self.projects = self.projects.split(',')
625 self.projects.append(self.arcconfig["project"]) 626 if not self.projects:
626 if "project.name" in self.arcconfig: 627 self.projects = []
627 self.projects.append(self.arcconfig["project.name"]) 628 if "project" in self.arcconfig:
628 if "projects" in self.arcconfig: 629 self.projects.append(self.arcconfig["project"])
629 for p in self.arcconfig["projects"].split(','): 630 if "project.name" in self.arcconfig:
630 self.projects.append(p) 631 self.projects.append(self.arcconfig["project.name"])
631 self.projects = [s.strip().lower() for s in self.projects] 632 if "projects" in self.arcconfig:
632 if len(self.projects) == 0: 633 for p in self.arcconfig["projects"].split(','):
633 self.die("No project has been defined.\n" 634 self.projects.append(p)
635 self.projects = [s.strip().lower() for s in self.projects]
636 if len(self.projects) == 0:
637 self.die("No project has been defined.\n"
634 "You can add 'projects': 'p1, p2' in your .arcconfig\n" 638 "You can add 'projects': 'p1, p2' in your .arcconfig\n"
635 "Aborting.") 639 "Aborting.")
636 640
@@ -741,7 +745,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
741 # commit message, case insensitive. It will confuse phabricator's 745 # commit message, case insensitive. It will confuse phabricator's
742 # parser if they appear in the subject or body of the commit message. 746 # parser if they appear in the subject or body of the commit message.
743 blacklist = ['title:', 'summary:', 'test plan:', 'testplan:', 747 blacklist = ['title:', 'summary:', 'test plan:', 'testplan:',
744 'tested:', 'tests:', 'reviewer:', 'reviewers:', 748 'tested:', 'reviewer:', 'reviewers:',
745 'reviewed by:', 'cc:', 'ccs:', 'subscriber:', 749 'reviewed by:', 'cc:', 'ccs:', 'subscriber:',
746 'subscribers:', 'project:', 'projects:', 750 'subscribers:', 'project:', 'projects:',
747 'maniphest task:', 'maniphest tasks:', 751 'maniphest task:', 'maniphest tasks:',
@@ -1022,16 +1026,11 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1022 return "refs/tags/phabricator/diff/%s" % diffid 1026 return "refs/tags/phabricator/diff/%s" % diffid
1023 1027
1024 def push_diff_to_staging(self, diff, commit): 1028 def push_diff_to_staging(self, diff, commit):
1025 if not self.staging_url:
1026 print(" * %sNo staging repo set, not pushing diff %s%s" % (
1027 Colors.FAIL, diff.diffid, Colors.ENDC))
1028 return None
1029
1030 print(" * Pushing diff %d on the staging repo... " % 1029 print(" * Pushing diff %d on the staging repo... " %
1031 diff.diffid, end='') 1030 diff.diffid, end='')
1032 try: 1031 try:
1033 remote_ref = self.get_diff_staging_ref(diff.diffid) 1032 remote_ref = self.get_diff_staging_ref(diff.diffid)
1034 self.repo.git.push(self.staging_url, "%s:%s" % (commit.hexsha, 1033 self.repo.git.push(self.remote, "%s:%s" % (commit.hexsha,
1035 remote_ref)) 1034 remote_ref))
1036 print("%sOK%s" % (Colors.OKGREEN, Colors.ENDC)) 1035 print("%sOK%s" % (Colors.OKGREEN, Colors.ENDC))
1037 1036
@@ -1108,7 +1107,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1108 1107
1109 # Make sure that we do no add dependency on already closed revision 1108 # Make sure that we do no add dependency on already closed revision
1110 # (avoiding making query on the server when not needed) 1109 # (avoiding making query on the server when not needed)
1111 if last_revision_id and \ 1110 if last_revision_id and not self.no_dependencies and \
1112 self.repo.head.commit.parents[0] not in proposed_commits and \ 1111 self.repo.head.commit.parents[0] not in proposed_commits and \
1113 not self.phabricator.differential.query( 1112 not self.phabricator.differential.query(
1114 ids=[last_revision_id], status="status-closed"): 1113 ids=[last_revision_id], status="status-closed"):
@@ -1123,6 +1122,47 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1123 arc_message = phab.differential.getcommitmessage( 1122 arc_message = phab.differential.getcommitmessage(
1124 revision_id=revision_id, edit="update", 1123 revision_id=revision_id, edit="update",
1125 fields=phab_fields).response 1124 fields=phab_fields).response
1125 if self.reviewers:
1126 tag_start = arc_message.find("Reviewers: ")
1127 reviewers = [r.strip() for r in self.reviewers.split(',')];
1128 if tag_start == -1:
1129 arc_message += "\nReviewers:"
1130 for reviewer in reviewers:
1131 arc_message += ' ' + reviewer + ','
1132 else:
1133 tag_end = arc_message.find('\n', tag_start)
1134 for reviewer in reviewers:
1135 if arc_message.find(reviewer, tag_start, tag_end) == -1:
1136 arc_message = arc_message.replace(
1137 "Reviewers: ",
1138 "Reviewers: " + reviewer + ', ')
1139 if self.cc:
1140 tag_start = arc_message.find("Subscribers: ")
1141 subscribers = [r.strip() for r in self.cc.split(',')];
1142 if tag_start == -1:
1143 arc_message += "\nSubscribers:"
1144 for subscriber in subscribers:
1145 arc_message += ' ' + subscriber + ','
1146 else:
1147 tag_end = arc_message.find('\n', tag_start)
1148 for subscriber in subscribers:
1149 if arc_message.find(subscriber, tag_start, tag_end) == -1:
1150 arc_message = arc_message.replace(
1151 "Subscribers: ",
1152 "Subscribers: " + subscriber + ', ')
1153 if self.project_phids:
1154 tag_start = arc_message.find("Tags: ")
1155 if tag_start == -1:
1156 arc_message += "\nTags:"
1157 for project in self.project_phids:
1158 arc_message += ' #' + project + ','
1159 else:
1160 tag_end = arc_message.find('\n', tag_start)
1161 for project in self.project_phids:
1162 if arc_message.find(project, tag_start, tag_end) == -1:
1163 arc_message = arc_message.replace(
1164 "Tags: ",
1165 "Tags: #" + project + ', ')
1126 else: 1166 else:
1127 arc_message = phab.differential.getcommitmessage( 1167 arc_message = phab.differential.getcommitmessage(
1128 edit="create", fields=phab_fields).response 1168 edit="create", fields=phab_fields).response
@@ -1151,6 +1191,10 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1151 arc_message = arc_message.replace( 1191 arc_message = arc_message.replace(
1152 "Subscribers: ", "Subscribers: " + self.cc) 1192 "Subscribers: ", "Subscribers: " + self.cc)
1153 1193
1194 arc_message += "\nTags:"
1195 for project in self.project_phids:
1196 arc_message += ' #' + project + ','
1197
1154 arc_message = '\n'.join([ 1198 arc_message = '\n'.join([
1155 l for l in arc_message.split("\n") 1199 l for l in arc_message.split("\n")
1156 if not l.startswith("#")]) 1200 if not l.startswith("#")])
@@ -1161,8 +1205,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1161 1205
1162 parsed_message = phab.differential.parsecommitmessage( 1206 parsed_message = phab.differential.parsecommitmessage(
1163 corpus=arc_message) 1207 corpus=arc_message)
1164
1165 fields = parsed_message["fields"] 1208 fields = parsed_message["fields"]
1209
1166 fields["title"] = subject 1210 fields["title"] = subject
1167 if not revision_id: 1211 if not revision_id:
1168 revision = phab.differential.createrevision(fields=fields, 1212 revision = phab.differential.createrevision(fields=fields,
@@ -1200,7 +1244,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1200 summary = "" 1244 summary = ""
1201 remote_uri = None 1245 remote_uri = None
1202 if staging_remote_refname and self.task: 1246 if staging_remote_refname and self.task:
1203 remote_uri = "%s#%s" % (self.staging_url, staging_remote_refname) 1247 remote_uri = "%s#%s" % (self.remote, staging_remote_refname)
1204 elif self.remote and self.task: 1248 elif self.remote and self.task:
1205 try: 1249 try:
1206 branch = self.get_wip_branch() 1250 branch = self.get_wip_branch()
@@ -1339,8 +1383,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1339 1383
1340 self.repo.git.commit("-n", amend=True, message=msg) 1384 self.repo.git.commit("-n", amend=True, message=msg)
1341 self.update_local_commit_info(diff, self.repo.head.object) 1385 self.update_local_commit_info(diff, self.repo.head.object)
1342 staging_remote_refname = self.push_diff_to_staging( 1386 # staging_remote_refname = self.push_diff_to_staging(
1343 diff, self.repo.head.object) 1387 # diff, self.repo.head.object)
1344 print("%s-> OK%s" % (Colors.OKGREEN, Colors.ENDC)) 1388 print("%s-> OK%s" % (Colors.OKGREEN, Colors.ENDC))
1345 1389
1346 summary += self.format_commit(self.repo.head.commit) + "\n" 1390 summary += self.format_commit(self.repo.head.commit) + "\n"
@@ -1560,12 +1604,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1560 self.repo.git.cherry_pick(new_commit.hexsha) 1604 self.repo.git.cherry_pick(new_commit.hexsha)
1561 1605
1562 def fetch_staging_commits(self, diff): 1606 def fetch_staging_commits(self, diff):
1563 if not self.staging_url:
1564 print("No staging URL")
1565 return False
1566
1567 try: 1607 try:
1568 self.repo.git.fetch(self.staging_url, 1608 self.repo.git.fetch(self.remote,
1569 self.get_diff_staging_ref(diff["id"])) 1609 self.get_diff_staging_ref(diff["id"]))
1570 except git.exc.GitCommandError as e: 1610 except git.exc.GitCommandError as e:
1571 print(e) 1611 print(e)
@@ -1806,7 +1846,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1806 if not self.fetch_staging_commits(diff): 1846 if not self.fetch_staging_commits(diff):
1807 return self.create_fake_fetch(revision, diff) 1847 return self.create_fake_fetch(revision, diff)
1808 1848
1809 return (self.repo.rev_parse("FETCH_HEAD"), self.staging_url, 1849 return (self.repo.rev_parse("FETCH_HEAD"), self.remote,
1810 self.clean_phab_branch_name(revision['branch'], 1850 self.clean_phab_branch_name(revision['branch'],
1811 self.differential)) 1851 self.differential))
1812 1852
@@ -2049,6 +2089,10 @@ if __name__ == '__main__':
2049 "any project(s) configured in .arcconfig)") \ 2089 "any project(s) configured in .arcconfig)") \
2050 .completer = DisabledCompleter 2090 .completer = DisabledCompleter
2051 attach_parser.add_argument( 2091 attach_parser.add_argument(
2092 '--no-dependencies', "-n", action="store_true",
2093 help="Do not apply dependencies of a revision.") \
2094 .completer = DisabledCompleter
2095 attach_parser.add_argument(
2052 'revision_range', metavar='<revision range>', 2096 'revision_range', metavar='<revision range>',
2053 nargs='?', default=None, 2097 nargs='?', default=None,
2054 help="commit or revision range to attach. When not specified, " 2098 help="commit or revision range to attach. When not specified, "