Merge pull request #117 from google/apply-patch
Manually specify commit to base patch
This commit is contained in:
commit
7e51fbcd8f
1 changed files with 11 additions and 6 deletions
|
@ -20,9 +20,10 @@ import sys
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from phabricator import Phabricator
|
from phabricator import Phabricator
|
||||||
|
|
||||||
|
|
||||||
class ApplyPatch:
|
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
|
# TODO: turn os.environ parameter into command line arguments
|
||||||
# this would be much clearer and easier for testing
|
# this would be much clearer and easier for testing
|
||||||
self.comment_file_path = comment_file_path
|
self.comment_file_path = comment_file_path
|
||||||
|
@ -34,7 +35,7 @@ class ApplyPatch:
|
||||||
if not self.host.endswith('/api/'):
|
if not self.host.endswith('/api/'):
|
||||||
self.host += '/api/'
|
self.host += '/api/'
|
||||||
self.phab = Phabricator(token=self.conduit_token, host=self.host)
|
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]
|
self.msg = [] # type: List[str]
|
||||||
|
|
||||||
def _load_arcrc(self):
|
def _load_arcrc(self):
|
||||||
|
@ -56,13 +57,16 @@ class ApplyPatch:
|
||||||
self.phab.update_interfaces()
|
self.phab.update_interfaces()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if self.git_hash is None:
|
||||||
self._get_parent_hash()
|
self._get_parent_hash()
|
||||||
|
else:
|
||||||
|
print('Use provided commit {}'.format(self.git_hash))
|
||||||
self._git_checkout()
|
self._git_checkout()
|
||||||
self._apply_patch()
|
self._apply_patch()
|
||||||
finally:
|
finally:
|
||||||
self._write_error_message()
|
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)
|
diff = self.phab.differential.getdiff(diff_id=self.diff_id)
|
||||||
# Keep a copy of the Phabricator answer for later usage in a json file
|
# Keep a copy of the Phabricator answer for later usage in a json file
|
||||||
try:
|
try:
|
||||||
|
@ -122,7 +126,8 @@ class ApplyPatch:
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Apply Phabricator patch to working directory.')
|
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('--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()
|
args = parser.parse_args()
|
||||||
patcher = ApplyPatch(args.comment_file_path)
|
patcher = ApplyPatch(args.comment_file_path, args.commit)
|
||||||
patcher.run()
|
patcher.run()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue