Skip to content

Instantly share code, notes, and snippets.

@Tyil
Forked from samcv/gitinfo.bash
Last active June 22, 2017 01:04
Show Gist options
  • Save Tyil/03de9dc9e4aa7fd4b5028e68aca2153d to your computer and use it in GitHub Desktop.
Save Tyil/03de9dc9e4aa7fd4b5028e68aca2153d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#set -e
#set -x
#set -v
function gitt () {
git tag --sort='-committerdate' --format=' %(authordate:relative)%09%(refname:short)'
}
function gitre () {
git remote -v
}
function gitb () {
git branch --sort='committerdate' --format=' %(authordate:relative)%09%(refname:short)';
}
mymodules="$(grep path .gitmodules | sed -re 's/\s*path\s*=\s*//')"
SAVEIFS="$IFS"
#IFS=$'\n'
modules_array=($mymodules)
#IFS="$SAVEIFS"
OWD="$(pwd)"
#DEBUG=1
the_titles=""
gitinfo () {
[[ "$DEBUG" ]] && printf "begin $1\n" 1>&2
MASTER_LAST_UPDATED=$(gitb | grep master)
current_commit="$(git log --oneline | head -n 1 | cut -d ' ' -f 1)"
TAG_LIST="$(gitt | sed -e 's|^|* |g')"
REPONAME="$(gitre | sed -re 's|.*github.com/(.*)(\.git)?.*|\1|g' | cut -d ' ' -f 1 | head -n 1)"
###>>>>
the_titles+="$the_titles $REPONAME"
###>>>>
LATEST_TAG="$(git tag --sort='committerdate' | head -n 1 | sed -re 's/\s+//g')"
master_diff="$(get_diff ${current_commit} master)"
printf "\n\n# %s\n\n" $REPONAME
printf "%s updated\n" "$MASTER_LAST_UPDATED"
[[ "$LATEST_TAG" ]] && printf "latest tag %s\n" "$LATEST_TAG";
if [[ "$LATEST_TAG" ]]; then
printf "Latest tag **%s**\n" "$LATEST_TAG";
printf "\n### Tag list: \n%s\n\n" "$TAG_LIST"
else
printf "There are no tags in this repo \n\n\n"
fi
printf '## Master git short log (%s..master)\n\n%s\n\n' "${current_commit}" "$master_diff"
if [[ "$LATEST_TAG" ]]; then
tagdiff="$(get_diff "${LATEST_TAG}" "${current_commit}" "$1" )"
printf "tagdiff range %s..%s\n" "${current_commit}" "${LATEST_TAG}"
printf "## Most recent tag diff shortlog\n\n%s\n\n\n" "${tagdiff}"
fi
}
function get_diff () {
[[ "$DEBUG" ]] && echo 'git log' "${1}..${2}" --no-merges --oneline 1>&2
printf '```\n'
git log "${1}..${2}" --no-merges --oneline
printf '\n```'
}
myvar=''
for i in $mymodules; do
cd -- "$OWD"
cd -- "$i"
temp="$(gitinfo "$i")"
full_text="$full_text$temp"
done
echo $the_titles
printf "%s\n" "$full_text"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment