Skip to content

Instantly share code, notes, and snippets.

@benspaulding
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benspaulding/b31b44b1a215ed342311 to your computer and use it in GitHub Desktop.
Save benspaulding/b31b44b1a215ed342311 to your computer and use it in GitHub Desktop.
Quick-and-dirty script to get some data about a repo
#!/usr/bin/env python
"""
Usage::
pip install gitpython
cd <repo>
analyze-repo
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import git
def main():
repo = git.Repo(os.getcwd())
commits = repo.git.rev_list(all=True).splitlines()
tested_commits = []
# Use git show to list the files changed in each commit
for commit in commits:
# We could get more precise with a regex, but 'in' is good enough & faster.
if 'test' in repo.git.show(commit, pretty='format:', name_only=True):
tested_commits.append(commit)
total_commits = len(commits)
commits_tested = len(tested_commits)
print('Total no. of commits: {0:>6,}'.format(total_commits));
print('No. of commits that touch tests: {0:>6,}'.format(commits_tested));
print('% of commits that touch tests: {0:>10.2%}'.format(commits_tested / total_commits))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment