summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@osg.samsung.com>2017-02-16 20:38:09 -0300
committerThibault Saunier <thibault.saunier@osg.samsung.com>2017-03-21 15:10:44 -0300
commit3f8e5f61ad866e93c46acea58f720adbe82d906f (patch)
tree28ec018ead5d39dd8059275e4fb5d8ef5ececda2
parentbdce4b379d68835c367948eac3e093465ff1163f (diff)
Use branches from staging repo to set task branches
No reason to use some other repo if a staging repo is avalaible. Also if no remote URI is set on the task we won't be able to later `git phab apply TXXX` because it is currently impossible to retrieve the list of differential associated to a task. Here we simply set the URI to the last published diff which contains the whole branch as expected. The following error was happenning: Can not apply revisions from a task if no 'remote branch' has been set for it. INFO: You need to find what revisions are associated with the tasks and apply them. Differential Revision: https://phabricator.freedesktop.org/D1672
-rwxr-xr-xgit-phab86
1 files changed, 52 insertions, 34 deletions
diff --git a/git-phab b/git-phab
index d7ceb1e..e2f6850 100755
--- a/git-phab
+++ b/git-phab
@@ -1018,23 +1018,29 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1018 1018
1019 return diff 1019 return diff
1020 1020
1021 def get_diff_staging_ref(self, diffid):
1022 return "refs/tags/phabricator/diff/%s" % diffid
1023
1021 def push_diff_to_staging(self, diff, commit): 1024 def push_diff_to_staging(self, diff, commit):
1022 if not self.staging_url: 1025 if not self.staging_url:
1023 print(" * %sNo staging repo set, not pushing diff %s%s" % ( 1026 print(" * %sNo staging repo set, not pushing diff %s%s" % (
1024 Colors.FAIL, diff.diffid, Colors.ENDC)) 1027 Colors.FAIL, diff.diffid, Colors.ENDC))
1025 return 1028 return None
1026 1029
1027 print(" * Pushing diff %d on the staging repo... " % 1030 print(" * Pushing diff %d on the staging repo... " %
1028 diff.diffid, end='') 1031 diff.diffid, end='')
1029 try: 1032 try:
1030 self.repo.git.push( 1033 remote_ref = self.get_diff_staging_ref(diff.diffid)
1031 self.staging_url, "%s:refs/tags/phabricator/diff/%s" % ( 1034 self.repo.git.push(self.staging_url, "%s:%s" % (commit.hexsha,
1032 commit.hexsha, diff.diffid)) 1035 remote_ref))
1033 print("%sOK%s" % (Colors.OKGREEN, Colors.ENDC)) 1036 print("%sOK%s" % (Colors.OKGREEN, Colors.ENDC))
1037
1038 return remote_ref
1034 except git.exc.GitCommandError as e: 1039 except git.exc.GitCommandError as e:
1035 print("%sERROR %s(%s)" % (Colors.FAIL, 1040 print("%sERROR %s(%s)" % (Colors.FAIL,
1036 Colors.ENDC, 1041 Colors.ENDC,
1037 e.stderr.decode("utf-8"))) 1042 e.stderr.strip("\n")))
1043 return None
1038 1044
1039 def update_local_commit_info(self, diff, commit): 1045 def update_local_commit_info(self, diff, commit):
1040 commit_infos = { 1046 commit_infos = {
@@ -1183,6 +1189,40 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1183 diffid=diff.diffid, 1189 diffid=diff.diffid,
1184 message=message), diff 1190 message=message), diff
1185 1191
1192 def update_task_branch_uri(self, staging_remote_refname):
1193 summary = ""
1194 remote_uri = None
1195 if staging_remote_refname and self.task:
1196 remote_uri = "%s#%s" % (self.staging_url, staging_remote_refname)
1197 elif self.remote and self.task:
1198 try:
1199 branch = self.get_wip_branch()
1200 remote = self.repo.remote(self.remote)
1201 if self.prompt('Push HEAD to %s/%s?' % (remote, branch)):
1202 info = remote.push('HEAD:refs/heads/' + branch,
1203 force=True)[0]
1204 if not info.flags & info.ERROR:
1205 summary += " * Branch pushed to %s/%s\n" % (remote,
1206 branch)
1207 else:
1208 print("-> Could not push branch %s/%s: %s" % (
1209 remote, branch, info.summary))
1210
1211 remote_uri = "%s#%s" % (self.remote_url, branch)
1212 except Exception as e:
1213 summary += " * Failed: push wip branch: %s\n" % e
1214
1215 if remote_uri:
1216 try:
1217 self.phabricator.maniphest.update(
1218 id=int(self.task[1:]),
1219 auxiliary={"std:maniphest:git:uri-branch": remote_uri})
1220 except:
1221 print("-> Failed to set std:maniphest:git:uri-branch to %s"
1222 % remote_uri)
1223
1224 return summary
1225
1186 @stash 1226 @stash
1187 def do_attach(self): 1227 def do_attach(self):
1188 # If we are in branch "T123" and user does "git phab attach -t T456", 1228 # If we are in branch "T123" and user does "git phab attach -t T456",
@@ -1251,6 +1291,7 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1251 orig_branch = self.repo.head.reference 1291 orig_branch = self.repo.head.reference
1252 1292
1253 patch_attachement_failure = False 1293 patch_attachement_failure = False
1294 staging_remote_refname = None
1254 try: 1295 try:
1255 # Detach HEAD from the branch; this gives a cleaner reflog for the 1296 # Detach HEAD from the branch; this gives a cleaner reflog for the
1256 # branch 1297 # branch
@@ -1291,7 +1332,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1291 1332
1292 self.repo.git.commit("-n", amend=True, message=msg) 1333 self.repo.git.commit("-n", amend=True, message=msg)
1293 self.update_local_commit_info(diff, self.repo.head.object) 1334 self.update_local_commit_info(diff, self.repo.head.object)
1294 self.push_diff_to_staging(diff, self.repo.head.object) 1335 staging_remote_refname = self.push_diff_to_staging(
1336 diff, self.repo.head.object)
1295 print("%s-> OK%s" % (Colors.OKGREEN, Colors.ENDC)) 1337 print("%s-> OK%s" % (Colors.OKGREEN, Colors.ENDC))
1296 1338
1297 summary += self.format_commit(self.repo.head.commit) + "\n" 1339 summary += self.format_commit(self.repo.head.commit) + "\n"
@@ -1309,31 +1351,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1309 self.repo.head.reset(index=True, working_tree=True) 1351 self.repo.head.reset(index=True, working_tree=True)
1310 raise 1352 raise
1311 1353
1312 if self.remote and self.task and not patch_attachement_failure: 1354 if not patch_attachement_failure:
1313 try: 1355 summary += self.update_task_branch_uri(staging_remote_refname)
1314 branch = self.get_wip_branch()
1315 remote = self.repo.remote(self.remote)
1316 if self.prompt('Push HEAD to %s/%s?' % (remote, branch)):
1317 info = remote.push('HEAD:refs/heads/' + branch,
1318 force=True)[0]
1319 if not info.flags & info.ERROR:
1320 summary += " * Branch pushed to %s/%s\n" % (remote,
1321 branch)
1322 else:
1323 print("-> Could not push branch %s/%s: %s" % (
1324 remote, branch, info.summary))
1325
1326 uri = "%s#%s" % (self.remote_url, branch)
1327 try:
1328 self.phabricator.maniphest.update(
1329 id=int(self.task[1:]),
1330 auxiliary={"std:maniphest:git:uri-branch": uri})
1331 except:
1332 print("-> Failed to set std:maniphest:git:uri-branch to %s"
1333 % uri)
1334
1335 except Exception as e:
1336 summary += " * Failed: push wip branch: %s\n" % e
1337 1356
1338 if self.task and not self.branch_task: 1357 if self.task and not self.branch_task:
1339 # Check if we already have a branch for this task 1358 # Check if we already have a branch for this task
@@ -1539,9 +1558,8 @@ Paste API Token from that page and press <enter>: """ % self.phabricator_uri)
1539 return False 1558 return False
1540 1559
1541 try: 1560 try:
1542 self.repo.git.fetch( 1561 self.repo.git.fetch(self.staging_url,
1543 self.staging_url, "refs/tags/phabricator/diff/%s" % 1562 self.get_diff_staging_ref(diff["id"]))
1544 diff["id"])
1545 except git.exc.GitCommandError as e: 1563 except git.exc.GitCommandError as e:
1546 print(e) 1564 print(e)
1547 return False 1565 return False