Skip to content

Instantly share code, notes, and snippets.

@yorammi
Created November 2, 2016 12:34
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 yorammi/e4b62da3d596bafd32a68bde1d9128eb to your computer and use it in GitHub Desktop.
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
#!/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