Manualy specify commit to base patch
useful for debugging
This commit is contained in:
parent
1bd9c4c4a9
commit
0e3a315ca9
1 changed files with 11 additions and 6 deletions
|
@ -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,17 +57,20 @@ class ApplyPatch:
|
|||
self.phab.update_interfaces()
|
||||
|
||||
try:
|
||||
self._get_parent_hash()
|
||||
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:
|
||||
with open(self.diff_json_path,'w') as json_file:
|
||||
with open(self.diff_json_path, 'w') as json_file:
|
||||
json.dump(diff.response, json_file, sort_keys=True, indent=4)
|
||||
print('Wrote diff details to "{}".'.format(self.diff_json_path))
|
||||
except Exception:
|
||||
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue