bpo-32256: Make patchcheck.py work for out-of-tree builds (GH-4760) · python/cpython@42c52a9 (original) (raw)

Original file line number Diff line number Diff line change
@@ -49,7 +49,9 @@ def get_git_branch():
49 49 """Get the symbolic name for the current git branch"""
50 50 cmd = "git rev-parse --abbrev-ref HEAD".split()
51 51 try:
52 -return subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
52 +return subprocess.check_output(cmd,
53 +stderr=subprocess.DEVNULL,
54 +cwd=SRCDIR)
53 55 except subprocess.CalledProcessError:
54 56 return None
55 57
@@ -61,7 +63,9 @@ def get_git_upstream_remote():
61 63 """
62 64 cmd = "git remote get-url upstream".split()
63 65 try:
64 -subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
66 +subprocess.check_output(cmd,
67 +stderr=subprocess.DEVNULL,
68 +cwd=SRCDIR)
65 69 except subprocess.CalledProcessError:
66 70 return "origin"
67 71 return "upstream"
@@ -99,7 +103,9 @@ def changed_files(base_branch=None):
99 103 else:
100 104 cmd = 'git status --porcelain'
101 105 filenames = []
102 -with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
106 +with subprocess.Popen(cmd.split(),
107 +stdout=subprocess.PIPE,
108 +cwd=SRCDIR) as st:
103 109 for line in st.stdout:
104 110 line = line.decode().rstrip()
105 111 status_text, filename = line.split(maxsplit=1)