@@ -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 )))
5151def 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
6379def report_modified_files (file_paths ):
0 commit comments