.github: Improve syncbranch debugability (#71596)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71596

Adds a dry_run to test out push as well as adding in a debug flag to
allow you to see what git commands are running

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>

Test Plan: Imported from OSS

Reviewed By: malfet, bigfootjon

Differential Revision: D33695224

Pulled By: seemethere

fbshipit-source-id: 03bf6a3f2d9594089e134d95c3d35a6779ba7a26
(cherry picked from commit a75a402f9d02d5e4c709e25ca385264f854945d1)
This commit is contained in:
Eli Uriegas
2022-01-20 15:46:15 -08:00
committed by PyTorch MergeBot
parent 64d221ffbf
commit 9adee84a3f
3 changed files with 14 additions and 7 deletions

View File

@ -99,11 +99,14 @@ def parse_fuller_format(lines: Union[str, List[str]]) -> GitCommit:
class GitRepo:
def __init__(self, path: str, remote: str = "origin") -> None:
def __init__(self, path: str, remote: str = "origin", debug: bool = False) -> None:
self.repo_dir = path
self.remote = remote
self.debug = debug
def _run_git(self, *args: Any) -> str:
if self.debug:
print(f"+ git -C {self.repo_dir} {' '.join(args)}")
return _check_output(["git", "-C", self.repo_dir] + list(args))
def revlist(self, revision_range: str) -> List[str]:
@ -183,11 +186,15 @@ class GitRepo:
self.checkout(orig_branch)
return
for commit in reversed(from_commits):
print(f"Cherry picking commit {commit}")
self.cherry_pick(commit)
self.checkout(orig_branch)
def push(self, branch: str) -> None:
self._run_git("push", self.remote, branch)
def push(self, branch: str, dry_run: bool) -> None:
if dry_run:
self._run_git("push", "--dry-run", self.remote, branch)
else:
self._run_git("push", self.remote, branch)
def head_hash(self) -> str:
return self._run_git("show-ref", "--hash", "HEAD").strip()