Skip to content

Instantly share code, notes, and snippets.

@mdtanrikulu
Last active March 23, 2020 09:47
Show Gist options
  • Save mdtanrikulu/85201a209cb85391dfb0d6e8d979af08 to your computer and use it in GitHub Desktop.
Save mdtanrikulu/85201a209cb85391dfb0d6e8d979af08 to your computer and use it in GitHub Desktop.
Git Monthly based Log Extractor
#!/bin/bash
# Usage
# **NOTE** Use at own risk!
# Improved version of this script: https://gist.github.com/pdobacz/90f8e204d4b2728c8b7e916f4bc279ae
# 1. checkout the desired branch in all relevant repos first!
# 2. `cd` into a dir where you can reference your repos by relative paths
# 3. ./main.sh <author> <Month Year> <Month Year> repo1 repo2 ... >
# Example
# ./main.sh "mdtanrikulu" Dec 2019 Jan 2020 ../my-repo/
set -xe
MONTHS=('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
function get_index() {
local index
for i in "${!MONTHS[@]}";
do
if [ "${MONTHS[$i]%,}" = "$1" ]; then
index=$i
fi
done
echo $index
}
AUTHOR=$1
shift
MONTH1=$1
shift
YEAR1=$1
shift
MONTH2=$1
shift
YEAR2=$1
shift
YEAR_DIFF=$(( $YEAR2-$YEAR1 ))
#2020 - 2018 = 2
if [ $YEAR_DIFF -gt 0 ]; then
YEAR_DIFF=$(( $YEAR_DIFF - 1))
fi
echo "YEAR DIFF $YEAR_DIFF"
MONTH_FROM=$(($(get_index $MONTH1) + 1))
#FEB = 2
MONTH_TO=$(($(get_index $MONTH2) + 1))
#MAR = 3
TOTAL_MONTH=$(( (12 - $MONTH_FROM) + $MONTH_TO + ($YEAR_DIFF * 12) ))
# 10 months from 2018 + 3 months from 2020 + 12 months form 2019 = 23
for (( i = $MONTH_FROM ; i <= $(( $TOTAL_MONTH + $MONTH_FROM )); i++ )); do
for REPO_PATH in "$@"; do
echo ""
echo "Repository: $REPO_PATH"
echo ""
DATE1="${MONTHS[$((($i - 1) % 12))]%,} 01 00:00:00 $YEAR1 +0100"
YEAR2=$YEAR1
if [ $(( $i % 12 )) -eq 0 ]; then
YEAR2=$(( $YEAR1 + 1 ))
fi
DATE2="${MONTHS[$(($i % 12))]%,} 01 00:00:00 $YEAR2 +0100"
REPO_NAME="${REPO_PATH///}"
REPO_NAME="${REPO_NAME//.}"
git \
-C $REPO_PATH --no-pager \
log \
--since="$DATE1" --until="$DATE2" \
--author="$AUTHOR" \
--reverse --date-order \
--patch --raw \
>> $(( $i - $MONTH_FROM + 1 ))-${MONTHS[$((($i - 1) % 12))]%,}-$YEAR1-$REPO_NAME.txt
YEAR1=$YEAR2
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment