3 from git_python
import Git
5 def commitsOfTouchedChanges(pathsChanged
):
6 """Returns a list of commits that touch the specified paths.
9 pathsChanged: A list of changed path relative to the current working dir.
12 A list of 40-character SHA's of the touched commits.
16 raise ValueError("No changed paths specified")
19 result
= git
.rev_list("HEAD", *pathsChanged
)
21 touched
= result
.split('\n')
23 # Don't return the trailing empty one
26 def pathsTouched(commit
, ignoreAddedFiles
):
27 """Returns a list of paths touched by a specific commit.
30 commit: A commit identifier as accepted by git-log.
31 ignoreAddedFiles: When True newly added files are ignored.
34 A list of paths touched by the specified commit.
37 result
= git
.log("--name-status", "-1", "--pretty=format:", commit
)
39 log
= result
.split('\n')
44 if len(line
.lstrip()) == 0:
47 splitline
= line
.split('\t')
48 if splitline
[0] == 'A' and ignoreAddedFiles
:
51 paths
.append(splitline
[1])
55 if __name__
== '__main__':
59 touched
= commitsOfTouchedChanges(["README"])
65 touched
= pathsTouched("HEAD", True)