mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-06 09:17:11 +08:00
.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:
committed by
PyTorch MergeBot
parent
64d221ffbf
commit
9adee84a3f
13
.github/scripts/gitutils.py
vendored
13
.github/scripts/gitutils.py
vendored
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user