Created
November 2, 2016 12:34
-
-
Save yorammi/e4b62da3d596bafd32a68bde1d9128eb to your computer and use it in GitHub Desktop.
Generate CSV file that lists all commits - since certain date - and lists all the branches each commit resides in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script arguments: | |
# SINCE - Date (format: MMM DD YYYY, e.g. Nov 1 2016) for list all commit since until now | |
# branches - comma-seperated list of branches to be set as columns in the resulted table | |
# the path to the resulted CSV file | |
CSV_FILE=COMMITS_REPORT.csv | |
# list all commits since given argument | |
all_commits=`git rev-list --remotes --since="$SINCE"` | |
# Header table line | |
echo -e "Commit Description,Commit ID,Date,Committer,$branches" > $CSV_FILE | |
# for each commit loop | |
for commit in $all_commits | |
do | |
# reset flag-per-commit whether to include it in the table | |
commitflag=0 | |
# calculate commit related values: commit message, date and committer | |
message=$(git show -s --pretty=format:"%s" $commit | tr '\n' ' ' | tr ',' ' ') | |
date=$(git show -s --pretty=format:"%cd" $commit) | |
committer=$(git show -s --pretty=format:"%cn" $commit | tr ',' ' ') | |
# initialize commit line | |
outline="$message,$commit,$date,$committer" | |
# list all branches related to the commit | |
commitbranches=`git branch -a --contains $commit` | |
# loop all the required branches | |
for branch in ${branches//,/ } | |
do | |
# reset flag indicating whether the commit is in the current checked branch | |
inflag=0 | |
# loop all the branches which the commit resides in | |
for commitbranch in $commitbranches | |
do | |
# validate match | |
if [ "$commitbranch" == "remotes/origin/$branch" ]; then | |
inflag=1 | |
commitflag=1 | |
fi | |
done | |
# add branch match flag to commit line | |
outline="$outline,$inflag" | |
done | |
if [ $commitflag -eq 1 ] ; then | |
# add commit line to table | |
echo -e "$outline" >> $CSV_FILE | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment