Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63693fe

Browse files
authored
Add option to skip branch creation in typeshed script (#20873)
While fixing typeshed merge conflicts, it's often necessary to run the script locally multiple times over. In these cases creating a new branch is undesirable.
1 parent 9268bf0 commit 63693fe

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

misc/sync-typeshed.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def main() -> None:
143143
action="store_true",
144144
help="Whether to make a PR with the changes (default to no)",
145145
)
146+
parser.add_argument("--no-branch", action="store_true", help="Skip creating a new branch")
146147
args = parser.parse_args()
147148

148149
check_state()
@@ -152,19 +153,23 @@ def main() -> None:
152153
raise ValueError("GITHUB_TOKEN environment variable must be set")
153154

154155
with tempfile.TemporaryDirectory() as tmpdir:
155-
# Stash patches before checking out a new branch
156-
typeshed_patches = os.path.join("misc", "typeshed_patches")
157-
tmp_patches = os.path.join(tmpdir, "typeshed_patches")
158-
shutil.copytree(typeshed_patches, tmp_patches)
159-
160-
branch_name = "mypybot/sync-typeshed"
161-
subprocess.run(["git", "checkout", "-B", branch_name, "origin/master"], check=True)
162-
163-
# Copy the stashed patches back
164-
shutil.rmtree(typeshed_patches, ignore_errors=True)
165-
shutil.copytree(tmp_patches, typeshed_patches)
166-
if subprocess.run(["git", "diff", "--quiet", "--exit-code"], check=False).returncode != 0:
167-
subprocess.run(["git", "commit", "-am", "Update typeshed patches"], check=True)
156+
if not args.no_branch:
157+
# Stash patches before checking out a new branch
158+
typeshed_patches = os.path.join("misc", "typeshed_patches")
159+
tmp_patches = os.path.join(tmpdir, "typeshed_patches")
160+
shutil.copytree(typeshed_patches, tmp_patches)
161+
162+
branch_name = "mypybot/sync-typeshed"
163+
subprocess.run(["git", "checkout", "-B", branch_name, "origin/master"], check=True)
164+
165+
# Copy the stashed patches back
166+
shutil.rmtree(typeshed_patches, ignore_errors=True)
167+
shutil.copytree(tmp_patches, typeshed_patches)
168+
if (
169+
subprocess.run(["git", "diff", "--quiet", "--exit-code"], check=False).returncode
170+
!= 0
171+
):
172+
subprocess.run(["git", "commit", "-am", "Update typeshed patches"], check=True)
168173

169174
if not args.typeshed_dir:
170175
tmp_typeshed = os.path.join(tmpdir, "typeshed")

0 commit comments

Comments
 (0)