Last active
January 10, 2023 14:45
-
-
Save benoit-ponsero/5764c1d250578c4829fbc129f885e8cd to your computer and use it in GitHub Desktop.
git log your repository and filter commit by dates and author. works with multiple repo. (useful for time tracking commits driven)
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 | |
start=$(date -v -30d +%Y-%m-%d) | |
stop=$(date +%Y-%m-%d) | |
author=$(git config user.name) | |
maxdepth=2 | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
--start=*) | |
start="${1#*=}" | |
;; | |
--stop=*) | |
stop="${1#*=}" | |
;; | |
--author=*) | |
author="${1#*=}" | |
;; | |
--depth=*) | |
maxdepth="${1#*=}" | |
;; | |
*) | |
printf "***************************\n" | |
printf "* Error: Invalid argument.*\n" | |
printf "***************************\n" | |
exit 1 | |
esac | |
shift | |
done | |
pwd="$(pwd)" | |
#echo $pwd | |
if [[ ! $start =~ "T" ]]; then | |
start="${start}T00:00:00" | |
fi | |
if [[ ! $stop =~ "T" ]]; then | |
stop="${stop}T23:59:59" | |
fi | |
gitlog() { | |
local path=$1 | |
commits="$(git --git-dir $path/.git log --author="""$author""" --after="""$start""" --before="""$stop""" --date=format:'%Y-%m-%d %H:%M' --pretty=format:'%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s' --color)" | |
if [ ! -z "$commits" ]; then | |
printf "\n$path\n" | |
echo -e "$commits" | |
fi | |
} | |
loop(){ | |
local path=$1 | |
local depth=${@: -1} | |
for d in $(ls "$path"); do | |
repo="$path/$d" | |
if [ -d "$repo/.git" ]; then | |
gitlog "$repo" | |
elif [[ -d "$repo" && $depth < $maxdepth ]]; then | |
loop $repo $(($depth+1)) | |
fi | |
done | |
} | |
if [ -d "$pwd/.git" ]; then | |
gitlog "$pwd" | |
else | |
loop $pwd 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment