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

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