tj.git-extras/bin/git-summary
jykntr bfeb897a6d git-summary correctly displays project name
git-summary correctly displays project name when not executed in the top
level directory of a repository.  Fixes tj/git-extras#302.

Uses the git-sh-setup script to find top level directory and then uses
that directory name for the project name.
2015-02-18 17:09:39 -07:00

89 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
SUBDIRECTORY_OK=Yes
source "$(git --exec-path)/git-sh-setup"
cd_to_toplevel
commit=""
test $# -ne 0 && commit=$@
project=${PWD##*/}
#
# get date for the given <commit>
#
date() {
git log --pretty='format: %ai' $1 | cut -d ' ' -f 2
}
#
# get active days for the given <commit>
#
active_days() {
date $1 | uniq | awk '
{ sum += 1 }
END { print sum }
'
}
#
# get the commit total
#
commit_count() {
git log --oneline $commit | wc -l | tr -d ' '
}
#
# total file count
#
file_count() {
git ls-files | wc -l | tr -d ' '
}
#
# list authors
#
authors() {
git shortlog -n -s $commit | awk '
{ args[NR] = $0; sum += $0 }
END {
for (i = 1; i <= NR; ++i) {
printf "%s,%2.1f%%\n", args[i], 100 * args[i] / sum
}
}
' | column -t -s,
}
#
# fetch repository age from oldest commit
#
repository_age() {
git log --reverse --pretty=oneline --format="%ar" | head -n 1 | sed 's/ago//'
}
# summary
if test "$1" = "--line"; then
git line-summary
echo
else
echo
echo " project : $project"
echo " repo age :" $(repository_age)
echo " active :" $(active_days) days
echo " commits :" $(commit_count)
if test "$commit" = ""; then
echo " files :" $(file_count)
fi
echo " authors : "
authors
echo
fi