Skip to content

Commit a1aa43b

Browse files
authored
cherry_picker now can only be run from CPython repo, (GH-148)
It can now be run from anywhere in CPython repo.
1 parent 155f473 commit a1aa43b

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

cherry_picker/cherry_picker/cherry_picker.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,10 @@ def cherry_pick_cli(dry_run, pr_remote, abort, status, push,
271271
commit_sha1, branches):
272272

273273
click.echo("\U0001F40D \U0001F352 \u26CF")
274-
current_dir = os.getcwd()
275-
pyconfig_path = os.path.join(current_dir, 'pyconfig.h.in')
276274

277-
if not os.path.exists(pyconfig_path):
278-
os.chdir(os.path.join(current_dir, 'cpython'))
275+
if not is_cpython_repo():
276+
click.echo("You're not inside a CPython repo right now! 🙅")
277+
sys.exit(-1)
279278

280279
if dry_run:
281280
click.echo("Dry run requested, listing expected command sequence")
@@ -320,5 +319,14 @@ def get_full_sha_from_short(short_sha):
320319
return full_sha
321320

322321

322+
def is_cpython_repo():
323+
cmd = "git log -r 7f777ed95a19224294949e1b4ce56bbffcb1fe9f"
324+
try:
325+
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
326+
except subprocess.SubprocessError:
327+
return False
328+
return True
329+
330+
323331
if __name__ == '__main__':
324332
cherry_pick_cli()

cherry_picker/cherry_picker/test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from .cherry_picker import get_base_branch, get_current_branch, \
6-
get_full_sha_from_short, CherryPicker
6+
get_full_sha_from_short, is_cpython_repo, CherryPicker
77

88

99
def test_get_base_branch():
@@ -97,3 +97,18 @@ def test_get_updated_commit_message(subprocess_check_output, os_path_exists):
9797
branches)
9898
assert cp.get_commit_message('22a594a0047d7706537ff2ac676cdc0f1dcb329c') \
9999
== 'bpo-123: Fix Spam Module (GH-113)'
100+
101+
@mock.patch('subprocess.check_output')
102+
def test_is_cpython_repo(subprocess_check_output):
103+
subprocess_check_output.return_value = """commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f
104+
Author: Guido van Rossum <[email protected]>
105+
Date: Thu Aug 9 14:25:15 1990 +0000
106+
107+
Initial revision
108+
109+
"""
110+
assert is_cpython_repo() == True
111+
112+
def test_is_not_cpython_repo():
113+
assert is_cpython_repo() == False
114+

0 commit comments

Comments
 (0)