diff options
author | Christian Heimes <christian@python.org> | 2015-04-23 09:25:41 (GMT) |
---|---|---|
committer | Christian Heimes <christian@python.org> | 2015-04-23 09:25:41 (GMT) |
commit | c314e28766fb58451488b38abdabc6161715e407 (patch) | |
tree | c0a04e1bdc558b20cce30cd7bfe31afb228d29ea /Tools | |
parent | 84de1bf2818308b8d1fd3d687ae3b7199f4462f2 (diff) | |
parent | d98c6773fa380848b75d55e652b4d5f40ac4d785 (diff) | |
download | cpython-c314e28766fb58451488b38abdabc6161715e407.zip cpython-c314e28766fb58451488b38abdabc6161715e407.tar.gz cpython-c314e28766fb58451488b38abdabc6161715e407.tar.bz2 |
Issue #24031: make patchcheck now supports git checkouts, too.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/patchcheck.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py index 1b51520..58b081a 100755 --- a/Tools/scripts/patchcheck.py +++ b/Tools/scripts/patchcheck.py @@ -49,15 +49,31 @@ def mq_patches_applied(): @status("Getting the list of files that have been added/changed", info=lambda x: n_files_str(len(x))) def changed_files(): - """Get the list of changed or added files from Mercurial.""" - if not os.path.isdir(os.path.join(SRCDIR, '.hg')): - sys.exit('need a checkout to get modified files') - - cmd = 'hg status --added --modified --no-status' - if mq_patches_applied(): - cmd += ' --rev qparent' - with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: - return [x.decode().rstrip() for x in st.stdout] + """Get the list of changed or added files from Mercurial or git.""" + if os.path.isdir(os.path.join(SRCDIR, '.hg')): + cmd = 'hg status --added --modified --no-status' + if mq_patches_applied(): + cmd += ' --rev qparent' + with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: + return [x.decode().rstrip() for x in st.stdout] + elif os.path.isdir(os.path.join(SRCDIR, '.git')): + cmd = 'git status --porcelain' + filenames = [] + with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: + for line in st.stdout: + line = line.decode().rstrip() + status = set(line[:2]) + # modified, added or unmerged files + if not status.intersection('MAU'): + continue + filename = line[3:] + if ' -> ' in filename: + # file is renamed + filename = filename.split(' -> ', 2)[1].strip() + filenames.append(filename) + return filenames + else: + sys.exit('need a Mercurial or git checkout to get modified files') def report_modified_files(file_paths): |