Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Created October 20, 2014 16:39
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 Janiczek/0aa9c7b262b3bf395b11 to your computer and use it in GitHub Desktop.
Save Janiczek/0aa9c7b262b3bf395b11 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Will generate CSV file with your commits. Columns:
# repository | branch | date | hash | message
# The file will be sorted by the date, and rows made unique.
# Expects to be run in a directory in form:
# .
# |- repo 1
# |- repo 2
# |- ...
# \- repo N
# Will create a report file ./report-<CURRENT-DATE>.csv
# TODO is there a way to find out the name of the branch the commit was commited to?
# (as opposed to being found in, which is what we check for now)
# TODO date range?
AUTHOR="Martin Janiczek";
PWD=`pwd`;
TMPFILE="$PWD/commits.txt";
DATE=`date +%Y-%m-%d`;
FILE="$PWD/report-$DATE.csv";
function get_repos {
REPOS=`echo */`;
for REPO in $REPOS;
do
REPO=${REPO%%/}; # ditch the /
echo "$REPO";
done;
}
function get_branches {
BRANCHES=`git for-each-ref --format='%(refname)' refs/{heads,remotes}/`;
for BRANCH in $BRANCHES;
do
BRANCH=$(basename "$BRANCH");
echo "$BRANCH";
done;
}
function list_commits {
SHA=`git rev-parse --short "$BRANCH" 2>/dev/null`;
IFS=$'\n';
COMMITS=`git shortlog --author="$AUTHOR" --format="%ai%x09%h%x09%s" "$SHA" 2>/dev/null | tail -n+2 | ghead -n-1`;
for COMMIT in $COMMITS;
do
COMMIT=`echo "$COMMIT" | gsed "s/ //"`;
echo -n ".";
echo -e "$REPO\t$BRANCH\t$COMMIT" >>"$TMPFILE";
done;
echo "";
}
for REPO in `get_repos`;
do
cd "$REPO";
for BRANCH in `get_branches`;
do
echo "looking at $REPO/$BRANCH";
list_commits;
done;
cd ..;
done;
sort -t $'\t' -k3,3 -u "$TMPFILE" >"$FILE";
rm -rf "$TMPFILE";
echo "Done writing to $FILE";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment