1
0
Fork 0

Manualy specify commit to base patch

useful for debugging
This commit is contained in:
Mikhail Goncharov 2020-02-03 13:35:13 +01:00
parent 1bd9c4c4a9
commit 0e3a315ca9

View file

@ -20,9 +20,10 @@ import sys
from typing import List, Optional
from phabricator import Phabricator
class ApplyPatch:
def __init__(self, comment_file_path: str):
def __init__(self, comment_file_path: str, git_hash: str):
# TODO: turn os.environ parameter into command line arguments
# this would be much clearer and easier for testing
self.comment_file_path = comment_file_path
@ -34,7 +35,7 @@ class ApplyPatch:
if not self.host.endswith('/api/'):
self.host += '/api/'
self.phab = Phabricator(token=self.conduit_token, host=self.host)
self.git_hash = None # type: Optional[str]
self.git_hash = git_hash # type: Optional[str]
self.msg = [] # type: List[str]
def _load_arcrc(self):
@ -56,13 +57,16 @@ class ApplyPatch:
self.phab.update_interfaces()
try:
if self.git_hash is None:
self._get_parent_hash()
else:
print('Use provided commit {}'.format(self.git_hash))
self._git_checkout()
self._apply_patch()
finally:
self._write_error_message()
def _get_parent_hash(self) -> str:
def _get_parent_hash(self):
diff = self.phab.differential.getdiff(diff_id=self.diff_id)
# Keep a copy of the Phabricator answer for later usage in a json file
try:
@ -122,7 +126,8 @@ class ApplyPatch:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Apply Phabricator patch to working directory.')
parser.add_argument('--comment-file', type=str, dest='comment_file_path', default=None)
parser.add_argument('--commit', type=str, dest='commit', default=None, help='use explicitly specified base commit')
args = parser.parse_args()
patcher = ApplyPatch(args.comment_file_path)
patcher = ApplyPatch(args.comment_file_path, args.commit)
patcher.run()