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

Skip to content

Commit d98c677

Browse files
committed
Issue #24031: make patchcheck now supports git checkouts, too.
1 parent 71f73ca commit d98c677

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ Documentation
225225

226226
- Issue #24029: Document the name binding behavior for submodule imports.
227227

228+
Tools/Demos
229+
-----------
230+
231+
- Issue #24031: make patchcheck now supports git checkouts, too.
228232

229233
What's New in Python 3.4.3?
230234
===========================

Tools/scripts/patchcheck.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,31 @@ def mq_patches_applied():
4949
@status("Getting the list of files that have been added/changed",
5050
info=lambda x: n_files_str(len(x)))
5151
def changed_files():
52-
"""Get the list of changed or added files from Mercurial."""
53-
if not os.path.isdir(os.path.join(SRCDIR, '.hg')):
54-
sys.exit('need a checkout to get modified files')
55-
56-
cmd = 'hg status --added --modified --no-status'
57-
if mq_patches_applied():
58-
cmd += ' --rev qparent'
59-
with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
60-
return [x.decode().rstrip() for x in st.stdout]
52+
"""Get the list of changed or added files from Mercurial or git."""
53+
if os.path.isdir(os.path.join(SRCDIR, '.hg')):
54+
cmd = 'hg status --added --modified --no-status'
55+
if mq_patches_applied():
56+
cmd += ' --rev qparent'
57+
with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
58+
return [x.decode().rstrip() for x in st.stdout]
59+
elif os.path.isdir(os.path.join(SRCDIR, '.git')):
60+
cmd = 'git status --porcelain'
61+
filenames = []
62+
with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
63+
for line in st.stdout:
64+
line = line.decode().rstrip()
65+
status = set(line[:2])
66+
# modified, added or unmerged files
67+
if not status.intersection('MAU'):
68+
continue
69+
filename = line[3:]
70+
if ' -> ' in filename:
71+
# file is renamed
72+
filename = filename.split(' -> ', 2)[1].strip()
73+
filenames.append(filename)
74+
return filenames
75+
else:
76+
sys.exit('need a Mercurial or git checkout to get modified files')
6177

6278

6379
def report_modified_files(file_paths):

0 commit comments

Comments
 (0)