3 from git_python
import Git
5 def stagedChanges(ignoreAddedFiles
):
6 """Returns the paths to all files that have changes staged.
7 When calling this function the current directory should be the root
8 of the git directory that should be acted on.
11 ignoreAddedFiles: When True files that added newly are ignored.
14 A list of paths that were changed.
18 result
= git
.diff_index("--cached", "--name-status", "HEAD")
20 log
= result
.split('\n')
25 # Skip the last empty line
26 if len(line
.lstrip()) == 0:
29 splitline
= line
.split('\t')
31 # Skip files that were freshly added
32 if splitline
[0] == 'A' and ignoreAddedFiles
:
35 changed
.append(splitline
[1])
39 if __name__
== '__main__':
43 staged
= stagedChanges(True)
46 print("No changes staged (or only new files added)")