6 from optparse
import OptionParser
7 from git_python
import Git
9 from git_stats
import commit
11 def stagedChanges(ignoreAddedFiles
=False):
12 """Returns the paths to all files that have changes staged.
13 When calling this function the current directory should be the root
14 of the git directory that should be acted on.
17 ignoreAddedFiles: When True files that added newly are ignored.
20 A list of paths that were changed.
24 result
= git
.diff_index("--cached", "--name-status", "HEAD")
26 log
= result
.split('\n')
31 # Skip the last empty line
32 if len(line
.lstrip()) == 0:
35 splitline
= line
.split('\t')
37 # Skip files that were freshly added
38 if splitline
[0] == 'A' and ignoreAddedFiles
:
41 changed
.append(splitline
[1])
46 """Returns which commits touched the same files as the staged changes.
49 showAll: When true, all files, even new ones, are searched.
51 Returns: If there were no staged changes, None is returned.
52 Otherwise the list of matching commits is returned.
55 staged
= stagedChanges(not showAll
)
60 touched
= commit
.commitsThatTouched(staged
)
64 """Dispatches index related commands
67 progname
= os
.path
.basename(sys
.argv
[0]) + " index"
69 parser
= OptionParser(prog
=progname
)
74 help="search even new files, which usually have no matching commits")
76 (options
, args
) = parser
.parse_args(list(args
))
78 result
= touched(options
.all
)
81 print("No changes staged (or only new files added)")
84 commit
.prettyPrint(result
)