mirror of
https://github.com/git-quick-stats/git-quick-stats.git
synced 2025-12-21 12:13:52 +01:00
Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
850b7453eb | ||
|
|
5063d1aad7 | ||
|
|
53b9971cf7 | ||
|
|
eec6d53ce9 | ||
|
|
d06a7ca090 | ||
|
|
462439a855 | ||
|
|
c467a9694b | ||
|
|
d4f71cfdad | ||
|
|
88e369503e | ||
|
|
afd61ce9c2 | ||
|
|
e1e02024a1 | ||
|
|
d1641f7bf3 | ||
|
|
8de8c43212 | ||
|
|
f4ec72073d | ||
|
|
b0003bef49 | ||
|
|
a833a5f431 | ||
|
|
886f64f086 | ||
|
|
115b21a48d | ||
|
|
4d515b88b3 | ||
|
|
9b3c0e5db1 | ||
|
|
86ad0af8bb | ||
|
|
fb488abe3e | ||
|
|
3cce04ddad | ||
|
|
d4e56cf557 | ||
|
|
cf239e5523 | ||
|
|
a0f495894b | ||
|
|
4faf233ad1 | ||
|
|
7d5087795e | ||
|
|
fe2df31c36 | ||
|
|
615563459f | ||
|
|
8c1d81a29d | ||
|
|
9f96cecf42 | ||
|
|
5b01b5e055 | ||
|
|
32a84903ff | ||
|
|
cd6d67df06 | ||
|
|
00d13c0b79 | ||
|
|
b525ed3b5c | ||
|
|
41a8542aaa | ||
|
|
7b1e0b2a65 | ||
|
|
43bc82520e | ||
|
|
d33ede9bcc | ||
|
|
7f24d202b9 | ||
|
|
62b128a3ce | ||
|
|
8515fe3a94 | ||
|
|
37bfde67ed | ||
|
|
d886facadf | ||
|
|
aa6619508a | ||
|
|
a813846c9f | ||
|
|
22bf354da4 | ||
|
|
0fea0323a4 | ||
|
|
4fcf8f5fef | ||
|
|
374aa2ef72 | ||
|
|
33dca7f3ed | ||
|
|
2ecb296442 | ||
|
|
428d25d0ef | ||
|
|
c3110e985e | ||
|
|
ebbeb34837 | ||
|
|
6cdca7c7c7 | ||
|
|
71d414eb4a | ||
|
|
d8346210a4 | ||
|
|
b85760e8b9 | ||
|
|
07ad3b57a7 | ||
|
|
dec1c4e103 | ||
|
|
2a0294941f |
5
.github/FUNDING.yml
vendored
5
.github/FUNDING.yml
vendored
@@ -1,6 +1 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [arzzen]
|
||||
open_collective: git-quick-stats
|
||||
ko_fi: lukasmestan
|
||||
custom: ['https://lukasmestan.com/thanks/']
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -7,4 +7,7 @@
|
||||
.Spotlight*
|
||||
.Trash*
|
||||
**/*~
|
||||
nbproject/*
|
||||
nbproject/*
|
||||
/tests/test-git/.git/
|
||||
#/tests/test-git/*
|
||||
!/tests/test-git/resetgit
|
||||
|
||||
4
.mailmap
4
.mailmap
@@ -1,3 +1,3 @@
|
||||
Lukas Mestan <lukas.mestan@gmail.com> Lukáš Mešťan <arzzen@users.noreply.github.com>
|
||||
Lukas Mestan <lukas.mestan@gmail.com> arzzen
|
||||
Lukas <test@gmail.com> Lukáš <arzzen@users.noreply.github.com>
|
||||
Lukas <lukas@gmail.com> arzzen
|
||||
|
||||
|
||||
@@ -23,5 +23,6 @@ ENV _GIT_SINCE= \
|
||||
TERM=xterm-256color
|
||||
|
||||
WORKDIR /git
|
||||
RUN git config --global --add safe.directory /git
|
||||
ENTRYPOINT [ "/usr/local/bin/docker-entrypoint" ]
|
||||
CMD [ "/usr/bin/git", "quick-stats" ]
|
||||
CMD [ "/usr/bin/git", "quick-stats" ]
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Lukáš Mešťan
|
||||
Copyright (c) 2024 git-quick-stats.sh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
5
Makefile
5
Makefile
@@ -3,6 +3,7 @@ _INSTDIR ?= $(DESTDIR)$(PREFIX)
|
||||
BINDIR ?= $(_INSTDIR)/bin
|
||||
MANDIR ?= $(_INSTDIR)/share/man
|
||||
TASK_DONE = echo -e "\n✓ $@ done\n"
|
||||
SHELL := $(shell which bash)
|
||||
|
||||
.PHONY: test
|
||||
|
||||
@@ -29,8 +30,8 @@ uninstall:
|
||||
@$(TASK_DONE)
|
||||
|
||||
reinstall:
|
||||
@curl -sO https://raw.githubusercontent.com/arzzen/git-quick-stats/master/git-quick-stats
|
||||
@curl -sO https://raw.githubusercontent.com/arzzen/git-quick-stats/master/git-quick-stats.1
|
||||
@curl -sO https://raw.githubusercontent.com/git-quick-stats/git-quick-stats/master/git-quick-stats
|
||||
@curl -sO https://raw.githubusercontent.com/git-quick-stats/git-quick-stats/master/git-quick-stats.1
|
||||
$(MAKE) install
|
||||
@$(TASK_DONE)
|
||||
|
||||
|
||||
127
README.md
127
README.md
@@ -1,11 +1,12 @@
|
||||
# GIT quick statistics [](https://twitter.com/intent/tweet?text=Simple%20and%20efficient%20way%20to%20access%20various%20statistics%20in%20git%20repository&url=https://github.com/arzzen/git-quick-stat&via=arzzen&hashtags=git,stats,tool,statistics,developers)
|
||||
|
||||
# GIT quick statistics [](#backers) [](#sponsors) [](https://twitter.com/intent/tweet?text=Simple%20and%20efficient%20way%20to%20access%20various%20statistics%20in%20git%20repository&url=https://github.com/arzzen/git-quick-stat&via=arzzen&hashtags=git,stats,tool,statistics,developers) [](https://travis-ci.org/arzzen/git-quick-stats) [](https://formulae.brew.sh/formula/git-quick-stats#default) [](https://repology.org/metapackage/git-quick-stats/packages)
|
||||
[](https://formulae.brew.sh/formula/git-quick-stats#default)
|
||||
|
||||
> `git-quick-stats` is a simple and efficient way to access various statistics in a git repository.
|
||||
>
|
||||
> Any git repository may contain tons of information about commits, contributors, and files. Extracting this information is not always trivial, mostly because there are a gadzillion options to a gadzillion git commands – I don’t think there is a single person alive who knows them all. Probably not even [Linus Torvalds](https://github.com/torvalds) himself :).
|
||||
> Any git repository may contain tons of information about commits, contributors, and files. Extracting this information is not always trivial, mostly because there are a gadzillion options to a gadzillion git commands - I don't think there is a single person alive who knows them all. Probably not even [Linus Torvalds](https://github.com/torvalds) himself :).
|
||||
|
||||

|
||||

|
||||
|
||||
## Table of Contents
|
||||
|
||||
@@ -13,34 +14,34 @@
|
||||
|
||||
[**Usage**](#usage)
|
||||
|
||||
* [**Interactive**](#interactive)
|
||||
* [**Non-interactive**](#non-interactive)
|
||||
* [**Command-line arguments**](#command-line-arguments)
|
||||
* [**Git log since and until**](#git-log-since-and-until)
|
||||
* [**Git log limit**](#git-log-limit)
|
||||
* [**Git log options**](#git-log-options)
|
||||
* [**Git pathspec**](#git-pathspec)
|
||||
* [**Git merge view strategy**](#git-merge-view-strategy)
|
||||
* [**Color themes**](#color-themes)
|
||||
- [**Interactive**](#interactive)
|
||||
- [**Non-interactive**](#non-interactive)
|
||||
- [**Command-line arguments**](#command-line-arguments)
|
||||
- [**Git log since and until**](#git-log-since-and-until)
|
||||
- [**Git log limit**](#git-log-limit)
|
||||
- [**Git log options**](#git-log-options)
|
||||
- [**Git pathspec**](#git-pathspec)
|
||||
- [**Git merge view strategy**](#git-merge-view-strategy)
|
||||
- [**Color themes**](#color-themes)
|
||||
|
||||
[**Installation**](#installation)
|
||||
|
||||
* [**UNIX and Linux**](#unix-and-linux)
|
||||
* [**macOS**](#macos-homebrew)
|
||||
* [**Windows**](#windows)
|
||||
* [**Docker**](#docker)
|
||||
- [**UNIX and Linux**](#unix-and-linux)
|
||||
- [**macOS**](#macos-homebrew)
|
||||
- [**Windows**](#windows)
|
||||
- [**Docker**](#docker)
|
||||
|
||||
[**System requirements**](#system-requirements)
|
||||
|
||||
* [**Dependencies**](#dependencies)
|
||||
- [**Dependencies**](#dependencies)
|
||||
|
||||
[**FAQ**](#faq)
|
||||
|
||||
[**Contribution**](#contribution)
|
||||
|
||||
* [**Code reviews**](#code-reviews)
|
||||
* [**Some tips for good pull requests**](#some-tips-for-good-pull-requests)
|
||||
* [**Formatting**](#formatting)
|
||||
- [**Code reviews**](#code-reviews)
|
||||
- [**Some tips for good pull requests**](#some-tips-for-good-pull-requests)
|
||||
- [**Formatting**](#formatting)
|
||||
|
||||
[**Tests**](#tests)
|
||||
|
||||
@@ -48,14 +49,14 @@
|
||||
|
||||
[**Contributors**](#contributors)
|
||||
|
||||
* [**Backers**](#backers)
|
||||
* [**Sponsors**](#sponsors)
|
||||
- [**Backers**](#backers)
|
||||
- [**Sponsors**](#sponsors)
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
@@ -115,14 +116,20 @@ LIST OPTIONS
|
||||
show branches by date
|
||||
-C, --contributors
|
||||
see a list of everyone who contributed to the repo
|
||||
-n, --new-contributors
|
||||
list everyone who made their first contribution since a specified date
|
||||
-a, --commits-per-author
|
||||
displays a list of commits per author
|
||||
-d, --commits-per-day
|
||||
displays a list of commits per day
|
||||
-Y, --commits-by-year
|
||||
displays a list of commits per year
|
||||
-m, --commits-by-month
|
||||
displays a list of commits per month
|
||||
-w, --commits-by-weekday
|
||||
displays a list of commits per weekday
|
||||
-W, --commits-by-author-by-weekday
|
||||
displays a list of commits per weekday by author
|
||||
-o, --commits-by-hour
|
||||
displays a list of commits per hour
|
||||
-A, --commits-by-author-by-hour
|
||||
@@ -152,7 +159,7 @@ Once set, run `git quick-stats` as normal. Note that this affects all stats that
|
||||
|
||||
### Git log limit
|
||||
|
||||
You can set variable `_GIT_LIMIT` for limited output. It will affect the "changelogs" and "branch tree" options.
|
||||
You can set variable `_GIT_LIMIT` for limited output. It will affect the "changelogs" and "branch tree" options. The default limit is `10`.
|
||||
|
||||
```bash
|
||||
export _GIT_LIMIT=20
|
||||
@@ -197,6 +204,12 @@ You can set the variable `_GIT_BRANCH` to set the branch of the stats. Works wit
|
||||
export _GIT_BRANCH="master"
|
||||
```
|
||||
|
||||
You can set the variable `_GIT_IGNORE_AUTHORS` to filter out specific authors. It will affect the "All contributors", ""Suggested code reviewers" and "New contributors" options.
|
||||
|
||||
```bash
|
||||
export _GIT_IGNORE_AUTHORS="(author@examle.com|username)"
|
||||
```
|
||||
|
||||
### Color themes
|
||||
|
||||
You can change to the legacy color scheme by toggling the variable `_MENU_THEME` between `default` and `legacy`
|
||||
@@ -205,7 +218,7 @@ You can change to the legacy color scheme by toggling the variable `_MENU_THEME`
|
||||
export _MENU_THEME="legacy"
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
@@ -220,7 +233,7 @@ apt install git-quick-stats
|
||||
### UNIX and Linux
|
||||
|
||||
```bash
|
||||
git clone https://github.com/arzzen/git-quick-stats.git && cd git-quick-stats
|
||||
git clone https://github.com/git-quick-stats/git-quick-stats.git && cd git-quick-stats
|
||||
sudo make install
|
||||
```
|
||||
|
||||
@@ -238,18 +251,34 @@ sudo make reinstall
|
||||
|
||||
### macOS (homebrew)
|
||||
|
||||
macOS requires GNU coreutils to be installed and for the non "g" aliased
|
||||
versions to be exported to your path. The following is an example of how to
|
||||
perform this if you are using Homebrew as your package manager.
|
||||
|
||||
```bash
|
||||
brew install coreutils
|
||||
export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
|
||||
```
|
||||
|
||||
From there, you can install via Homebrew as follows:
|
||||
|
||||
```bash
|
||||
brew install git-quick-stats
|
||||
```
|
||||
|
||||
Or you can follow the UNIX and Linux instructions if you wish.
|
||||
|
||||
If you would like to default to using the GNU coreutils (recommended), then you
|
||||
can add `export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"` to
|
||||
your applicable `~/.bash_profile`, `~/.zprofile`, or other relevant profile
|
||||
based on the shell of your choice.
|
||||
|
||||
### Windows
|
||||
|
||||
If you are installing with Cygwin, use these scripts:
|
||||
|
||||
* [installer](https://gist.github.com/arzzen/35e09866dfdadf2108b2420045739245)
|
||||
* [uninstaller](https://gist.github.com/arzzen/21c660014d0663b6c5710014714779d6)
|
||||
- [installer](https://gist.github.com/arzzen/35e09866dfdadf2108b2420045739245)
|
||||
- [uninstaller](https://gist.github.com/arzzen/21c660014d0663b6c5710014714779d6)
|
||||
|
||||
If you are wishing to use this with WSL, follow the UNIX and Linux instructions.
|
||||
|
||||
@@ -257,20 +286,21 @@ If you are wishing to use this with WSL, follow the UNIX and Linux instructions.
|
||||
|
||||
You can use the Docker image provided:
|
||||
|
||||
* Build: `docker build -t arzzen/git-quick-stats .`
|
||||
* Run interactive menu: `docker run --rm -it -v $(pwd):/git arzzen/git-quick-stats`
|
||||
* Docker pull command: `docker pull arzzen/git-quick-stats` [docker repository](https://hub.docker.com/r/arzzen/git-quick-stats)
|
||||
- Build: `docker build -t arzzen/git-quick-stats .`
|
||||
- Run interactive menu: `docker run --rm -it -v $(pwd):/git arzzen/git-quick-stats`
|
||||
- Docker pull command: `docker pull arzzen/git-quick-stats` [docker repository](https://hub.docker.com/r/arzzen/git-quick-stats)
|
||||
|
||||
## System requirements
|
||||
|
||||
* An OS with a Bash shell
|
||||
* Tools we use:
|
||||
- An OS with a Bash shell
|
||||
- Tools we use:
|
||||
|
||||
```bash
|
||||
awk
|
||||
basename
|
||||
cat
|
||||
column
|
||||
date
|
||||
echo
|
||||
git
|
||||
grep
|
||||
@@ -281,22 +311,25 @@ sort
|
||||
tput
|
||||
tr
|
||||
uniq
|
||||
wc
|
||||
```
|
||||
|
||||
### Dependencies
|
||||
|
||||
* [`bsdmainutils`](https://packages.debian.org/sid/bsdmainutils) `apt install bsdmainutils`
|
||||
- [`bsdextrautils`](https://packages.debian.org/sid/bsdextrautils) `apt install bsdextrautils`
|
||||
- [`coreutils`](https://packages.debian.org/sid/coreutils) `apt install coreutils`
|
||||
- [`gawk`](https://packages.debian.org/sid/gawk) `apt install gawk`
|
||||
- [`grep`](https://packages.debian.org/sid/grep) `apt install grep`
|
||||
- [`ncurses-bin`](https://packages.debian.org/sid/ncurses-bin) `apt install ncurses-bin`
|
||||
|
||||
## FAQ
|
||||
|
||||
*Q:* I get some errors after run git-quick-stats in cygwin like `/usr/local/bin/git-quick-stats: line 2: $'\r': command not found`
|
||||
_Q:_ I get some errors after run git-quick-stats in cygwin like `/usr/local/bin/git-quick-stats: line 2: $'\r': command not found`
|
||||
|
||||
*A:* You can run the dos2unix app in cygwin as follows: `/bin/dos2unix.exe /usr/local/bin/git-quick-stats`. This will convert the script from the CR-LF convention that Microsoft uses to the LF convention that UNIX, OS X, and Linux use. You should then should be able to run it as normal.
|
||||
_A:_ You can run the dos2unix app in cygwin as follows: `/bin/dos2unix.exe /usr/local/bin/git-quick-stats`. This will convert the script from the CR-LF convention that Microsoft uses to the LF convention that UNIX, OS X, and Linux use. You should then should be able to run it as normal.
|
||||
|
||||
*Q:* How they could be used in a project with many git projects and statistics would show a summary of all git projects?
|
||||
_Q:_ How they could be used in a project with many git projects and statistics would show a summary of all git projects?
|
||||
|
||||
*A:* If you want to include submodule logs, you can try using the following: `export _GIT_LOG_OPTIONS="-p --submodule=log"`
|
||||
_A:_ If you want to include submodule logs, you can try using the following: `export _GIT_LOG_OPTIONS="-p --submodule=log"`
|
||||
(more info about [git log --submodule](https://git-scm.com/docs/git-log#Documentation/git-log.txt---submoduleltformatgt))
|
||||
|
||||
## Contribution
|
||||
@@ -310,13 +343,13 @@ We use GitHub pull requests for this purpose.
|
||||
|
||||
### Some tips for good pull requests
|
||||
|
||||
* Use our code </br>
|
||||
- Use our code </br>
|
||||
When in doubt, try to stay true to the existing code of the project.
|
||||
* Write a descriptive commit message. What problem are you solving and what
|
||||
- Write a descriptive commit message. What problem are you solving and what
|
||||
are the consequences? Where and what did you test? Some good tips:
|
||||
[here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
|
||||
and [here](https://www.kernel.org/doc/Documentation/SubmittingPatches).
|
||||
* If your PR consists of multiple commits which are successive improvements /
|
||||
- If your PR consists of multiple commits which are successive improvements /
|
||||
fixes to your first commit, consider squashing them into a single commit
|
||||
(`git rebase -i`) such that your PR is a single commit on top of the current
|
||||
HEAD. This make reviewing the code so much easier, and our history more
|
||||
@@ -338,15 +371,15 @@ make test
|
||||
|
||||
MIT see [LICENSE][] for the full license text.
|
||||
|
||||
[read this page]: http://github.com/arzzen/git-quick-stats/blob/master/.github/CONTRIBUTING.md
|
||||
[landing page]: http://arzzen.github.io/git-quick-stats
|
||||
[LICENSE]: https://github.com/arzzen/git-quick-stats/blob/master/LICENSE
|
||||
[read this page]: http://github.com/git-quick-stats/git-quick-stats/blob/master/.github/CONTRIBUTING.md
|
||||
[landing page]: https://git-quick-stats.sh
|
||||
[LICENSE]: https://github.com/git-quick-stats/git-quick-stats/blob/master/LICENSE
|
||||
|
||||
## Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
|
||||
[](https://github.com/arzzen/git-quick-stats/graphs/contributors)
|
||||
[](https://github.com/git-quick-stats/git-quick-stats/graphs/contributors)
|
||||
|
||||
### Backers
|
||||
|
||||
|
||||
481
git-quick-stats
481
git-quick-stats
@@ -11,13 +11,13 @@ set -o nounset
|
||||
set -o errexit
|
||||
|
||||
# Beginning git log date. Respects all git datetime formats
|
||||
# If $_GIT_SINCE is never set, choose epoch time as that is
|
||||
# as far back as git will allow you to go
|
||||
# If $_GIT_SINCE is never set, look at the repository to find the first date.
|
||||
# NOTE: previously this put the date at the fixed GIT epoch (May 2005)
|
||||
_since=${_GIT_SINCE:-}
|
||||
if [[ -n "${_since}" ]]; then
|
||||
_since="--since=$_since"
|
||||
else
|
||||
_since="--since=2005-04-07"
|
||||
_since="--since=$(git log --reverse --format='%ad' --date=iso | head -n1)"
|
||||
fi
|
||||
|
||||
# End of git log date. Respects all git datetime formats
|
||||
@@ -27,7 +27,7 @@ _until=${_GIT_UNTIL:-}
|
||||
if [[ -n "${_until}" ]]; then
|
||||
_until="--until=$_until"
|
||||
else
|
||||
_until="--until=$(date)"
|
||||
_until="--until=$(LC_TIME=C date '+%a, %d %b %Y %H:%M:%S %Z')"
|
||||
fi
|
||||
|
||||
# Set files or directories to be excluded in stats
|
||||
@@ -68,10 +68,68 @@ else
|
||||
_log_options=""
|
||||
fi
|
||||
|
||||
# Ignore author regex
|
||||
_ignore_authors=${_GIT_IGNORE_AUTHORS:-}
|
||||
if [[ -n "${_ignore_authors}" ]]; then
|
||||
_ignore_authors=$_ignore_authors
|
||||
else
|
||||
_ignore_authors=""
|
||||
fi
|
||||
|
||||
# Default menu theme
|
||||
# Set the legacy theme by typing "export _MENU_THEME=legacy"
|
||||
_theme="${_MENU_THEME:=default}"
|
||||
|
||||
# DESC: Shows a calendar heatmap of commits per day-of-week per month for a given author
|
||||
# ARGS: $author (required)
|
||||
function commitsCalendarByAuthor() {
|
||||
local author="${1:-}"
|
||||
[[ -z "$author" ]] && { echo "Usage: commitsCalendarByAuthor <author>"; return 1; }
|
||||
|
||||
optionPicked "Commit Activity Calendar for '$author'"
|
||||
|
||||
# Print header
|
||||
printf "\n Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n"
|
||||
|
||||
# Gather commit counts
|
||||
git -c log.showSignature=false log --use-mailmap $_merges \
|
||||
--date=iso --author="$author" "$_since" "$_until" $_log_options \
|
||||
--pretty='%ad' $_pathspec | awk '
|
||||
{
|
||||
split($0, a, " ");
|
||||
# a[1] = YYYY-MM-DD
|
||||
split(a[1], date_fields, "-");
|
||||
mon = date_fields[2] + 0;
|
||||
cmd = "date -d \"" a[1] "\" +%u";
|
||||
cmd | getline weekday;
|
||||
close(cmd);
|
||||
# weekday: 1=Mon, ..., 7=Sun
|
||||
count[weekday][mon]++;
|
||||
}
|
||||
END {
|
||||
# Output matrix
|
||||
for (d=1; d<=7; d++) {
|
||||
if (d==1) printf "Mon ";
|
||||
else if (d==2) printf "Tue ";
|
||||
else if (d==3) printf "Wed ";
|
||||
else if (d==4) printf "Thu ";
|
||||
else if (d==5) printf "Fri ";
|
||||
else if (d==6) printf "Sat ";
|
||||
else if (d==7) printf "Sun ";
|
||||
for (m=1; m<=12; m++) {
|
||||
c = count[d][m]+0;
|
||||
if (c==0) out="...";
|
||||
else if (c<=9) out="░░░";
|
||||
else if (c<=19) out="▒▒▒";
|
||||
else out="▓▓▓";
|
||||
printf "%s%s", out, (m<12?" ":"\n");
|
||||
}
|
||||
}
|
||||
printf "\nLegend: ... = 0 ░░░ = 1–9 ▒▒▒ = 10–19 ▓▓▓ = 20+ commits\n";
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# HELPER AND MENU FUNCTIONS
|
||||
|
||||
@@ -82,13 +140,29 @@ _theme="${_MENU_THEME:=default}"
|
||||
################################################################################
|
||||
function checkUtils() {
|
||||
readonly MSG="not found. Please make sure this is installed and in PATH."
|
||||
readonly UTILS="awk basename cat column echo git grep head printf seq sort \
|
||||
tput tr uniq wc"
|
||||
readonly UTILS="awk basename cat column date echo git grep head printf seq \
|
||||
sort tput tr uniq"
|
||||
|
||||
for u in $UTILS
|
||||
do
|
||||
command -v "$u" >/dev/null 2>&1 || { echo >&2 "$u ${MSG}"; exit 1; }
|
||||
done
|
||||
|
||||
# NOTE: The --version flag is only available in GNU date which is required
|
||||
# for how the current date/time strings are used in this shell script.
|
||||
# To fully support the legacy BSD date found in a default install within
|
||||
# macOS and older distributions of Linux and Unix, a handful of helper
|
||||
# functions can probably be created to handle every case of incompatibility
|
||||
# between the two. Until that's implemented, it is probably best to warn
|
||||
# the user that this will not work rather than having it silently bomb out
|
||||
# during runtime.
|
||||
if ! date --version >/dev/null 2>&1; then
|
||||
echo "ERROR: GNU date is required."
|
||||
echo "If you're on macOS, please install it using 'brew install coreutils'."
|
||||
echo "Ensure that your PATH is configured to use GNU date as well."
|
||||
echo "See the README.md for further details."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -148,14 +222,20 @@ LIST OPTIONS
|
||||
show branches by date
|
||||
-C, --contributors
|
||||
see a list of everyone who contributed to the repo
|
||||
-n, --new-contributors
|
||||
list everyone who made their first contribution since a specified date
|
||||
-a, --commits-per-author
|
||||
displays a list of commits per author
|
||||
-d, --commits-per-day
|
||||
displays a list of commits per day
|
||||
-m, --commits-by-month
|
||||
displays a list of commits per month
|
||||
-Y, --commits-by-year
|
||||
displays a list of commits per year
|
||||
-w, --commits-by-weekday
|
||||
displays a list of commits per weekday
|
||||
-W, --commits-by-author-by-weekday
|
||||
displays a list of commits per weekday by author
|
||||
-o, --commits-by-hour
|
||||
displays a list of commits per hour
|
||||
-A, --commits-by-author-by-hour
|
||||
@@ -187,7 +267,9 @@ ADDITIONAL USAGE
|
||||
You can set _MENU_THEME to display the legacy color scheme
|
||||
ex: export _MENU_THEME=legacy
|
||||
You can set _GIT_BRANCH to set the branch of the stats
|
||||
ex: export _GIT_BRANCH=master"
|
||||
ex: export _GIT_BRANCH=master
|
||||
You can set _GIT_IGNORE_AUTHORS to filter out specific authors
|
||||
ex: export _GIT_IGNORE_AUTHORS=\"(author1|author2)\""
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -236,21 +318,34 @@ function showMenu() {
|
||||
printf %b "${NUMS} 8)${TEXT} Branch tree view (last $_limit)\\n"
|
||||
printf %b "${NUMS} 9)${TEXT} All branches (sorted by most recent commit)\\n"
|
||||
printf %b "${NUMS} 10)${TEXT} All contributors (sorted by name)\\n"
|
||||
printf %b "${NUMS} 11)${TEXT} Git commits per author\\n"
|
||||
printf %b "${NUMS} 12)${TEXT} Git commits per date\\n"
|
||||
printf %b "${NUMS} 13)${TEXT} Git commits per month\\n"
|
||||
printf %b "${NUMS} 14)${TEXT} Git commits per weekday\\n"
|
||||
printf %b "${NUMS} 15)${TEXT} Git commits per hour\\n"
|
||||
printf %b "${NUMS} 16)${TEXT} Git commits per hour by author\\n"
|
||||
printf %b "${NUMS} 17)${TEXT} Git commits per timezone\\n"
|
||||
printf %b "${NUMS} 18)${TEXT} Git commits per timezone by author\\n"
|
||||
printf %b "${NUMS} 11)${TEXT} New contributors (sorted by email)\\n"
|
||||
printf %b "${NUMS} 12)${TEXT} Git commits per author\\n"
|
||||
printf %b "${NUMS} 13)${TEXT} Git commits per date\\n"
|
||||
printf %b "${NUMS} 14)${TEXT} Git commits per month\\n"
|
||||
printf %b "${NUMS} 15)${TEXT} Git commits per year\\n"
|
||||
printf %b "${NUMS} 16)${TEXT} Git commits per weekday\\n"
|
||||
printf %b "${NUMS} 17)${TEXT} Git commits per weekday by author\\n"
|
||||
printf %b "${NUMS} 18)${TEXT} Git commits per hour\\n"
|
||||
printf %b "${NUMS} 19)${TEXT} Git commits per hour by author\\n"
|
||||
printf %b "${NUMS} 20)${TEXT} Git commits per timezone\\n"
|
||||
printf %b "${NUMS} 21)${TEXT} Git commits per timezone by author\\n"
|
||||
printf %b "\\n${TITLES} Suggest:\\n"
|
||||
printf %b "${NUMS} 19)${TEXT} Code reviewers (based on git history)\\n"
|
||||
printf %b "${NUMS} 22)${TEXT} Code reviewers (based on git history)\\n"
|
||||
printf %b "\\n${TITLES} Calendar:\\n"
|
||||
printf %b "${NUMS} 23)${TEXT} Activity calendar by author\\n"
|
||||
printf %b "\\n${HELP_TXT}Please enter a menu option or ${EXIT_TXT}press Enter to exit.\\n"
|
||||
printf %b "${TEXT}> ${NORMAL}"
|
||||
read -r opt
|
||||
}
|
||||
|
||||
filter_ignored_authors() {
|
||||
if [[ -n "$_ignore_authors" ]]; then
|
||||
grep -Ev "$_ignore_authors"
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# FUNCTIONS FOR GENERATING STATS
|
||||
|
||||
@@ -297,11 +392,15 @@ function detailedGitStats() {
|
||||
if(more["total"] > 0) {
|
||||
printf "\t insertions: %d\t(%.0f%%)\n", more[author], \
|
||||
(more[author] / more["total"] * 100)
|
||||
} else {
|
||||
printf "\t insertions: %d\t(%.0f%%)\n", 0, 0
|
||||
}
|
||||
|
||||
if(less["total"] > 0) {
|
||||
printf "\t deletions: %d\t(%.0f%%)\n", less[author], \
|
||||
(less[author] / less["total"] * 100)
|
||||
} else {
|
||||
printf "\t deletions: %d\t(%.0f%%)\n", 0, 0
|
||||
}
|
||||
|
||||
if(file["total"] > 0) {
|
||||
@@ -369,8 +468,9 @@ function detailedGitStats() {
|
||||
# OUTS: None
|
||||
################################################################################
|
||||
function changelogs() {
|
||||
local author="${1:-}"
|
||||
local _author=""
|
||||
local commits=""
|
||||
local author="${1:-}"
|
||||
local next=$(date +%F)
|
||||
|
||||
if [[ -z "${author}" ]]; then
|
||||
@@ -388,13 +488,20 @@ function changelogs() {
|
||||
--date=short "${_author}" "$_since" "$_until" $_log_options $_pathspec \
|
||||
| sort -u -r | head -n $_limit \
|
||||
| while read DATE; do
|
||||
echo -e "\n[$DATE]"
|
||||
GIT_PAGER=cat git -c log.showSignature=false log \
|
||||
--use-mailmap $_merges \
|
||||
--format=" * %s (%aN)" "${_author}" \
|
||||
--since=$DATE --until=$next
|
||||
next=$DATE
|
||||
done
|
||||
commits=$(git -c log.showSignature=false log \
|
||||
--use-mailmap $_merges \
|
||||
--format=" * %s (%aN)" "${_author}" \
|
||||
--since="$DATE 00:00:00" --until="$DATE 23:59:59" \
|
||||
--date-order)
|
||||
|
||||
if [[ -n "$commits" ]]; then
|
||||
echo -e "\n[$DATE]"
|
||||
echo "$commits"
|
||||
else
|
||||
echo "No commits found on $DATE"
|
||||
fi
|
||||
next=$DATE
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -416,7 +523,7 @@ function myDailyStats() {
|
||||
--author="$(git config user.name)" $_merges \
|
||||
--since=$(date "+%Y-%m-%dT00:00:00") \
|
||||
--until=$(date "+%Y-%m-%dT23:59:59") --reverse $_log_options \
|
||||
| grep -E "commit [a-f0-9]{40}" | wc -l) "commits"
|
||||
| grep -cE "commit [a-f0-9]{40}") "commits"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -451,17 +558,21 @@ function csvOutput() {
|
||||
printf "files_per,commits,commits_per,lines_changed,lines_changed_per\n"
|
||||
git -c log.showSignature=false log ${_branch} --use-mailmap $_merges --numstat \
|
||||
--pretty="format:commit %H%nAuthor: %aN <%aE>%nDate: %ad%n%n%w(0,4,4)%B%n" \
|
||||
"$_since" "$_until" $_log_options $_pathspec | LC_ALL=C awk '
|
||||
"$_since" "$_until" $_log_options $_pathspec | filter_ignored_authors | LC_ALL=C awk '
|
||||
function printStats(author) {
|
||||
printf "%s,", author
|
||||
if(more["total"] > 0) {
|
||||
printf "%d,%.0f%%,", more[author], \
|
||||
(more[author] / more["total"] * 100)
|
||||
} else {
|
||||
printf "0,0%%,"
|
||||
}
|
||||
|
||||
if(less["total"] > 0) {
|
||||
printf "%d,%.0f%%,", less[author], \
|
||||
(less[author] / less["total"] * 100)
|
||||
} else {
|
||||
printf "0,0%%,"
|
||||
}
|
||||
|
||||
if(file["total"] > 0) {
|
||||
@@ -516,6 +627,67 @@ function csvOutput() {
|
||||
}'
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Transforms special multiline string sequence to a JSON string property.
|
||||
# {propTag}{optional white space indentation}{property}
|
||||
# {line1}
|
||||
# {line2}
|
||||
# ...
|
||||
# {propTag}, (the final comma is optional)
|
||||
# Generates: "{property}": "{line1}\n{line2}\n...",
|
||||
# The final comma is added if present after the ending tag.
|
||||
# Caveat: the content should not contain {propTag} at the
|
||||
# beginning of a line.
|
||||
# ARGS: $propTag (optional) : tag at the beginning of the line to mark the
|
||||
# beginning and the end of a special sequence. It must not contain
|
||||
# regular expression special characters, i.e. use [a-zA-Z0-9_]+.
|
||||
# This tag should be sufficiently random to avoid collision with
|
||||
# the actual content. Defaults to __JSONPROP__.
|
||||
# OUTS: content with JSON string properties
|
||||
################################################################################
|
||||
function toJsonProp() {
|
||||
local propTag="${1:-__JSONPROP__}"
|
||||
sed -n -E '
|
||||
# transforms the special sequence.
|
||||
/^'"$propTag"'[^\r]/ {
|
||||
# remove the special prefix, keep the property name followed by :
|
||||
s/^'"$propTag"'([^\r]+)\r?$/\1:/g;
|
||||
# hold in buffer, get the next line.
|
||||
h;n
|
||||
# loop
|
||||
b eos
|
||||
:eos {
|
||||
# add in hold buffer and loop while the string is not finished.
|
||||
/^'"$propTag"',?\r?$/ ! { H; n; b eos; }
|
||||
# end of the string, flip buffer to current pattern.
|
||||
# keeps the comma if any, or a space as an empty placeholder.
|
||||
/,\r?$/ ! { x; s/\r?$/ / }
|
||||
/,\r?$/ { x; s/\r?$/,/ }
|
||||
}
|
||||
# replace special JSON string chars.
|
||||
s/["\\]/\\&/g;
|
||||
# replace control chars, carriage returns, line feeds, tabulations, etc.
|
||||
s/\x00/\\u0000/g; s/\x01/\\u0001/g; s/\x02/\\u0002/g; s/\x03/\\u0003/g;
|
||||
s/\x04/\\u0004/g; s/\x05/\\u0005/g; s/\x06/\\u0006/g; s/\x07/\\u0007/g;
|
||||
s/\x08/\\b/g; s/\x09/\\t/g; s/\x0a/\\n/g; s/\x0b/\\u000b/g;
|
||||
s/\x0c/\\f/g; s/\x0d/\\r/g; s/\x0e/\\u000e/g; s/\x0f/\\u000f/g;
|
||||
s/\x10/\\u0010/g; s/\x11/\\u0011/g; s/\x12/\\u0012/g; s/\x13/\\u0013/g;
|
||||
s/\x14/\\u0014/g; s/\x15/\\u0015/g; s/\x16/\\u0016/g; s/\x17/\\u0017/g;
|
||||
s/\x18/\\u0018/g; s/\x19/\\u0019/g; s/\x1a/\\u001a/g; s/\x1b/\\u001b/g;
|
||||
s/\x1c/\\u001c/g; s/\x1d/\\u001d/g; s/\x1e/\\u001e/g; s/\x1f/\\u001f/g;
|
||||
s/\x7f/\\u007f/g;
|
||||
|
||||
# format the JSON property name, optionally indented, open quote for value.
|
||||
s/^(\s*)([^:]+):\\n/\1"\2": "/g;
|
||||
# handle the final comma if present, and close the quote for value.
|
||||
/,$/ { s/,$/",/g; }
|
||||
# otherwise remove final space placeholder and close the quote for value.
|
||||
/,$/ ! { s/ $/"/g; }
|
||||
}
|
||||
# print lines.
|
||||
p'
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Saves the git log output in a JSON format
|
||||
# ARGS: $json_path (required): Path to where the file is saved
|
||||
@@ -523,10 +695,20 @@ function csvOutput() {
|
||||
################################################################################
|
||||
function jsonOutput() {
|
||||
optionPicked "Output log saved to file at: ${json_path}/output.json"
|
||||
# TODO: Can we shorten this pretty format line? Quick experiment shows that
|
||||
# it does not properly respect \ and interprets them literally.
|
||||
local propTag="__JSONPROP${RANDOM}__"
|
||||
git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" $_log_options \
|
||||
--pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n "subject": "%s",%n "sanitized_subject_line": "%f",%n "body": "%b",%n "commit_notes": "%N",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%aD"%n },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "date": "%cD"%n }%n},' \
|
||||
--pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n'\
|
||||
' "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n'\
|
||||
"$propTag"' subject%n%s%n'"$propTag"',%n "sanitized_subject_line": "%f",%n'\
|
||||
"$propTag"' body%n%b%n'"$propTag"',%n'\
|
||||
"$propTag"' commit_notes%n%N%n'"$propTag"',%n "author": {%n'\
|
||||
"$propTag"' name%n%aN%n'"$propTag"',%n'\
|
||||
"$propTag"' email%n%aE%n'"$propTag"',%n'\
|
||||
' "date": "%aD"%n },%n "committer": {%n'\
|
||||
"$propTag"' name%n%cN%n'"$propTag"',%n'\
|
||||
"$propTag"' email%n%cE%n'"$propTag"',%n'\
|
||||
' "date": "%cD"%n }%n},' \
|
||||
| toJsonProp "$propTag" \
|
||||
| sed "$ s/,$//" \
|
||||
| sed ':a;N;$!ba;s/\r\n\([^{]\)/\\n\1/g' \
|
||||
| awk 'BEGIN { print("[") } { print($0) } END { print("]") }' \
|
||||
@@ -570,7 +752,27 @@ function branchesByDate() {
|
||||
function contributors() {
|
||||
optionPicked "All contributors (sorted by name):"
|
||||
git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" \
|
||||
--format='%aN' $_log_options $_pathspec | sort -u | cat -n
|
||||
--format='%aN' $_log_options $_pathspec | filter_ignored_authors | sort -u | cat -n
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Lists all new contributors to a repo since the specified time
|
||||
# ARGS: $newDate (required): Cutoff date for being considered "new"
|
||||
# OUTS: None
|
||||
################################################################################
|
||||
function newContributors() {
|
||||
optionPicked "New contributors since $newDate:"
|
||||
local contributors=$(git -c log.showSignature=false log --use-mailmap $_merges \
|
||||
"$_since" "$_until" --format='%aE' $_log_options \
|
||||
$_pathspec | sort -u)
|
||||
for c in $contributors; do
|
||||
local firstCommit=$(git -c log.showSignature=false log --author="$c" \
|
||||
--reverse --use-mailmap $_merges "$_since" "$_until" \
|
||||
--format='%at' $_log_options $_pathspec | filter_ignored_authors | head -n 1)
|
||||
if [[ $firstCommit -ge $(date -d "$newDate" +%s) ]]; then
|
||||
echo "$c"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -583,10 +785,10 @@ function commitsPerAuthor() {
|
||||
optionPicked "Git commits per author:"
|
||||
local authorCommits=$(git -c log.showSignature=false log --use-mailmap \
|
||||
$_merges "$_since" "$_until" $_log_options \
|
||||
| grep -i Author: | cut -c9-)
|
||||
| grep -i '^Author:' | cut -c9-)
|
||||
local coAuthorCommits=$(git -c log.showSignature=false log --use-mailmap \
|
||||
$_merges "$_since" "$_until" $_log_options \
|
||||
| grep -i Co-Authored-by: | cut -c21-)
|
||||
| grep -i '^ Co-Authored-by:' | cut -c21-)
|
||||
|
||||
if [[ -z "${coAuthorCommits}" ]]; then
|
||||
allCommits="${authorCommits}"
|
||||
@@ -618,6 +820,105 @@ function commitsPerDay() {
|
||||
--date=short --format='%ad' $_log_options $_pathspec | sort | uniq -c
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Convert a timestamp to a date string to handle git's date formats
|
||||
# ARGS: $1: Timestamp
|
||||
# OUTS: Echoes a four-digit year
|
||||
################################################################################
|
||||
function parse_year() {
|
||||
local date_str="$1"
|
||||
local year
|
||||
local timestamp
|
||||
local default_git_date_regex
|
||||
|
||||
# Handle the raw UNIX timestamp format i.e. 1697375696 +0000
|
||||
if [[ "$date_str" =~ ^[0-9]+(\ [+-][0-9]{4})?$ ]]; then
|
||||
timestamp=$(echo "$date_str" | awk '{print $1}')
|
||||
year=$(date -d "@$timestamp" '+%Y' 2>/dev/null)
|
||||
else
|
||||
# Default case can get funky. We need to create a clever regex to
|
||||
# handle the default case which is like Mon Oct 15 12:34:56 2023 +0000
|
||||
# Let's make this explicit for future devs to follow along.
|
||||
default_git_date_regex='^' # Start from the beginning of the string
|
||||
default_git_date_regex+='[A-Za-z]{3}\ ' # Day abbrev
|
||||
default_git_date_regex+='[A-Za-z]{3}\ ' # Month abbrev
|
||||
default_git_date_regex+='[0-9]{1,2}\ ' # Day of the month
|
||||
default_git_date_regex+='[0-9]{2}:[0-9]{2}:[0-9]{2}\ ' # Time HH:MM:SS
|
||||
default_git_date_regex+='[0-9]{4}\ ' # Year
|
||||
default_git_date_regex+='[+-][0-9]{4}$' # Timezone offset
|
||||
|
||||
if [[ "$date_str" =~ $default_git_date_regex ]]; then
|
||||
# Move the year before the time to match a format that Date can parse
|
||||
date_str=$(echo "$date_str" | awk '{print $1, $2, $3, $5, $4, $6}')
|
||||
elif [[ "$date_str" =~ ^[0-9]{1,2}/[0-9]{1,2}/[0-9]{2,4} ]]; then
|
||||
# Handle DD/MM/YYYY format
|
||||
date_str=$(echo "$date_str" | awk -F'/' '{print $2"/"$1"/"$3}')
|
||||
fi
|
||||
# Extract the final date
|
||||
year=$(date -d "$date_str" '+%Y' 2>/dev/null)
|
||||
fi
|
||||
|
||||
echo "$year"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Displays a horizontal bar graph based on total commits per year
|
||||
# ARGS: None
|
||||
# OUTS: None
|
||||
################################################################################
|
||||
function commitsByYear() {
|
||||
optionPicked "Git commits by year:"
|
||||
local year startYear endYear __since __until
|
||||
|
||||
# Extract the date strings from $_since and $_until
|
||||
since_date="${_since#--since=}"
|
||||
until_date="${_until#--until=}"
|
||||
|
||||
# Grab the four digit year from $_since and $_until
|
||||
startYear=$(parse_year "$since_date")
|
||||
endYear=$(parse_year "$until_date")
|
||||
|
||||
echo -e "\tyear\tsum"
|
||||
# Add time strings to make these a touch more robust
|
||||
for year in $(seq "$startYear" "$endYear"); do
|
||||
if [[ "$year" = "$startYear" ]]; then
|
||||
__since=$_since
|
||||
__until="--until=$year-12-31 23:59:59"
|
||||
elif [[ "$year" = "$endYear" ]]; then
|
||||
__since="--since=$year-01-01 00:00:00"
|
||||
__until=$_until
|
||||
else
|
||||
__since="--since=$year-01-01 00:00:00"
|
||||
__until="--until=$year-12-31 23:59:59"
|
||||
fi
|
||||
|
||||
# Count commits directly using git rev-list instead of git log
|
||||
commit_count=$(
|
||||
git rev-list --count $_merges \
|
||||
"$__since" "$__until" HEAD $_log_options
|
||||
)
|
||||
echo -e "\t$year\t$commit_count"
|
||||
# TODO: The bar graph can get funky when there are only a handful of
|
||||
# commits. We can set a max length to try to fix this, but this is a
|
||||
# bit of a problem across all the bar graphs.
|
||||
done | awk '{
|
||||
count[$1] = $2
|
||||
total += $2
|
||||
}
|
||||
END{
|
||||
for (year in count) {
|
||||
s="|";
|
||||
if (total > 0) {
|
||||
percent = ((count[year] / total) * 100) / 1.25;
|
||||
for (i = 1; i <= percent; ++i) {
|
||||
s=s"█"
|
||||
}
|
||||
printf( "\t%s\t%-0s\t%s\n", year, count[year], s );
|
||||
}
|
||||
}
|
||||
}' | sort
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# DESC: Displays a horizontal bar graph based on total commits per month
|
||||
# ARGS: None
|
||||
@@ -626,14 +927,13 @@ function commitsPerDay() {
|
||||
function commitsByMonth() {
|
||||
optionPicked "Git commits by month:"
|
||||
echo -e "\tmonth\tsum"
|
||||
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
|
||||
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
|
||||
local i
|
||||
for i in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
|
||||
do
|
||||
echo -en "\t$i\t"
|
||||
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
|
||||
"$_since" "$_until" $_log_options | grep -E "($startYear|$endYear)" \
|
||||
| grep " $i " | wc -l
|
||||
"$_since" "$_until" $_log_options |
|
||||
grep -cE " \w\w\w $i [0-9]{1,2} " || continue
|
||||
done | awk '{
|
||||
count[$1] = $2
|
||||
total += $2
|
||||
@@ -658,17 +958,25 @@ function commitsByMonth() {
|
||||
# OUTS: None
|
||||
################################################################################
|
||||
function commitsByWeekday() {
|
||||
optionPicked "Git commits by weekday:"
|
||||
local author="${1:-}"
|
||||
local _author=""
|
||||
|
||||
if [[ -z "${author}" ]]; then
|
||||
optionPicked "Git commits by weekday:"
|
||||
_author="--author=**"
|
||||
else
|
||||
optionPicked "Git commits by weekday for author '${author}':"
|
||||
_author="--author=${author}"
|
||||
fi
|
||||
|
||||
echo -e "\tday\tsum"
|
||||
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
|
||||
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
|
||||
local counter=1
|
||||
local i counter=1
|
||||
for i in Mon Tue Wed Thu Fri Sat Sun
|
||||
do
|
||||
echo -en "\t$counter\t$i\t"
|
||||
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
|
||||
"$_since" "$_until" $_log_options | grep -E "($startYear|$endYear)" \
|
||||
| grep "$i " | wc -l
|
||||
"${_author}" "$_since" "$_until" $_log_options |
|
||||
grep -cE "^ * $i \w\w\w [0-9]{1,2} " || continue
|
||||
counter=$((counter+1))
|
||||
done | awk '{
|
||||
}
|
||||
@@ -710,14 +1018,13 @@ function commitsByHour() {
|
||||
fi
|
||||
echo -e "\thour\tsum"
|
||||
|
||||
local startYear=$(echo "$_since" | grep -Eo "[0-9]{4}")
|
||||
local endYear=$(echo "$_until" | grep -Eo "[0-9]{4}")
|
||||
local i
|
||||
for i in $(seq -w 0 23)
|
||||
do
|
||||
echo -ne "\t$i\t"
|
||||
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
|
||||
"${_author}" "$_since" "$_until" $_log_options \
|
||||
| grep -E "($startYear|$endYear)" | grep ' '$i: | wc -l
|
||||
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
|
||||
"${_author}" "$_since" "$_until" $_log_options |
|
||||
grep -cE '[0-9] '$i':[0-9]' || continue
|
||||
done | awk '{
|
||||
count[$1] = $2
|
||||
total += $2
|
||||
@@ -754,9 +1061,9 @@ function commitsByTimezone() {
|
||||
fi
|
||||
|
||||
echo -e "Commits\tTimeZone"
|
||||
git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \
|
||||
git -c log.showSignature=false log $_merges --format='%ad %s' \
|
||||
"${_author}" "$_since" "$_until" --date=iso $_log_options $_pathspec \
|
||||
| cut -d " " -f 12 | grep -v -e '^[[:space:]]*$' | sort | uniq -c
|
||||
| cut -d " " -f 3 | grep -v -e '^[[:space:]]*$' | sort -n | uniq -c
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -771,7 +1078,7 @@ function suggestReviewers() {
|
||||
optionPicked "Suggested code reviewers (based on git history):"
|
||||
git -c log.showSignature=false log --use-mailmap $_merges "$_since" "$_until" \
|
||||
--pretty=%aN $_log_options $_pathspec | head -n 100 | sort | uniq -c \
|
||||
| sort -nr | LC_ALL=C awk '
|
||||
| filter_ignored_authors | sort -nr | LC_ALL=C awk '
|
||||
{ args[NR] = $0; }
|
||||
END {
|
||||
for (i = 1; i <= NR; ++i) {
|
||||
@@ -787,7 +1094,11 @@ function suggestReviewers() {
|
||||
checkUtils
|
||||
|
||||
# Check if we are currently in a git repo.
|
||||
git rev-parse --is-inside-work-tree > /dev/null
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null; then
|
||||
echo "ERROR: You need to be inside a git repo to parse stats!"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse non-interative commands
|
||||
if [[ "$#" -eq 1 ]]; then
|
||||
@@ -836,10 +1147,31 @@ if [[ "$#" -eq 1 ]]; then
|
||||
-b|--branch-tree) branchTree;;
|
||||
-D|--branches-by-date) branchesByDate;;
|
||||
-C|--contributors) contributors;;
|
||||
-n|--new-contributors)
|
||||
newDate=""
|
||||
while [[ -z "${newDate}" ]]; do
|
||||
read -r -p "Since what date? (e.g. '2023-04-13', '13 April 2023', 'last Thursday') " newDate
|
||||
# Test if the date provide is valid and try again if it isn't.
|
||||
# date(1) is pretty accepting of time stamps but you never know
|
||||
# what people may try. This script doesn't provide any additional
|
||||
# output for a bad date since `date`'s STDERR already contains
|
||||
# useful information.
|
||||
if ! date -d "${newDate}" +%s > /dev/null 2>&1; then
|
||||
newDate=""
|
||||
fi
|
||||
done
|
||||
newContributors "${newDate}";;
|
||||
-a|--commits-per-author) commitsPerAuthor;;
|
||||
-d|--commits-per-day) commitsPerDay;;
|
||||
-Y|--commits-by-year ) commitsByYear;;
|
||||
-m|--commits-by-month) commitsByMonth;;
|
||||
-w|--commits-by-weekday) commitsByWeekday;;
|
||||
-W|--commits-by-author-by-weekday)
|
||||
author="${_GIT_AUTHOR:-}"
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsByWeekday "${author}";;
|
||||
-o|--commits-by-hour) commitsByHour;;
|
||||
-A|--commits-by-author-by-hour)
|
||||
author="${_GIT_AUTHOR:-}"
|
||||
@@ -848,12 +1180,19 @@ if [[ "$#" -eq 1 ]]; then
|
||||
done
|
||||
commitsByHour "${author}";;
|
||||
-z|--commits-by-timezone) commitsByTimezone;;
|
||||
-Z|--commits-by-author-by-timezone)
|
||||
-Z|--commits-by-author-by-timezone)
|
||||
author="${_GIT_AUTHOR:-}"
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsByTimezone "${author}";;
|
||||
# ACTIVITY OPTIONS
|
||||
-k|--commits-calendar-by-author)
|
||||
author="${_GIT_AUTHOR:-}"
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsCalendarByAuthor "${author}";;
|
||||
# SUGGEST OPTIONS
|
||||
-r|--suggest-reviewers) suggestReviewers;;
|
||||
-h|-\?|--help) usage;;
|
||||
@@ -908,23 +1247,43 @@ while [[ "${opt}" != "" ]]; do
|
||||
8) branchTree; showMenu;;
|
||||
9) branchesByDate; showMenu;;
|
||||
10) contributors; showMenu;;
|
||||
11) commitsPerAuthor; showMenu;;
|
||||
12) commitsPerDay; showMenu;;
|
||||
13) commitsByMonth; showMenu;;
|
||||
14) commitsByWeekday; showMenu;;
|
||||
15) commitsByHour; showMenu;;
|
||||
16) author=""
|
||||
11) newDate=""
|
||||
while [[ -z "${newDate}" ]]; do
|
||||
read -r -p "Since what date? (e.g. '2023-04-13', '13 April 2023', 'last Thursday') " newDate
|
||||
# Test if the date provide is valid and try again if it isn't.
|
||||
if ! date -d "${newDate}" +%s > /dev/null 2>&1; then
|
||||
newDate=""
|
||||
fi
|
||||
done
|
||||
newContributors "${newDate}"; showMenu;;
|
||||
12) commitsPerAuthor; showMenu;;
|
||||
13) commitsPerDay; showMenu;;
|
||||
14) commitsByMonth; showMenu;;
|
||||
15) commitsByYear; showMenu;;
|
||||
16) commitsByWeekday; showMenu;;
|
||||
17) author=""
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsByWeekday "${author}"; showMenu;;
|
||||
18) commitsByHour; showMenu;;
|
||||
19) author=""
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsByHour "${author}"; showMenu;;
|
||||
17) commitsByTimezone; showMenu;;
|
||||
18) author=""
|
||||
20) commitsByTimezone; showMenu;;
|
||||
21) author=""
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsByTimezone "${author}"; showMenu;;
|
||||
19) suggestReviewers; showMenu;;
|
||||
22) suggestReviewers; showMenu;;
|
||||
23) author=""
|
||||
while [[ -z "${author}" ]]; do
|
||||
read -r -p "Which author? " author
|
||||
done
|
||||
commitsCalendarByAuthor "${author}"; showMenu;;
|
||||
q|"\n") exit;;
|
||||
*) clear; optionPicked "Pick an option from the menu"; showMenu;;
|
||||
esac
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH git-quick-stats "1" "June 2021" "git-quick-stats" "User Commands"
|
||||
.TH git-quick-stats "1" "June 2025" "git-quick-stats" "User Commands"
|
||||
.SH NAME
|
||||
.B git\-quick\-stats
|
||||
\- Simple and efficient way to access various stats in a git repository.
|
||||
@@ -70,6 +70,11 @@ show branches by date
|
||||
see a list of everyone who contributed to the repo
|
||||
.HP
|
||||
.PP
|
||||
\fB\-n\fR, \fB\-\-new\-contributors\fR
|
||||
.IP
|
||||
list everyone who made their first contribution since a specified date
|
||||
.HP
|
||||
.PP
|
||||
\fB\-a\fR, \fB\-\-commits\-per\-author\fR
|
||||
.IP
|
||||
displays a list of commits per author
|
||||
@@ -85,11 +90,21 @@ displays a list of commits per day
|
||||
displays a list of commits per month
|
||||
.HP
|
||||
.PP
|
||||
\fB\-Y\fR, \fB\-\-commits\-by\-year\fR
|
||||
.IP
|
||||
displays a list of commits per year
|
||||
.HP
|
||||
.PP
|
||||
\fB\-w\fR, \fB\-\-commits\-by\-weekday\fR
|
||||
.IP
|
||||
displays a list of commits per weekday
|
||||
.HP
|
||||
.PP
|
||||
\fB\-W\fR, \fB\-\-commits\-by\-author\-by\-weekday\fR
|
||||
.IP
|
||||
displays a list of commits per weekday by author
|
||||
.HP
|
||||
.PP
|
||||
\fB\-o\fR, \fB\-\-commits\-by\-hour\fR
|
||||
.IP
|
||||
displays a list of commits per hour
|
||||
@@ -109,6 +124,11 @@ displays a list of commits per timezone
|
||||
.IP
|
||||
displays a list of commits per timezone by author
|
||||
.HP
|
||||
.PP
|
||||
\fB\-\-activity\-calendar\fR
|
||||
.IP
|
||||
displays a calendar-style grid of commit activity per day-of-week and month for a selected author.
|
||||
.HP
|
||||
.SH SUGGEST OPTIONS
|
||||
.PP
|
||||
\fB\-r\fR, \fB\-\-suggest\-reviewers\fR
|
||||
@@ -152,5 +172,35 @@ You can switch to the legacy color scheme, example:
|
||||
You can set _GIT_BRANCH to set the branch of the stats, example:
|
||||
.PP
|
||||
.B export _GIT_BRANCH="master"
|
||||
.PP
|
||||
.SH Calendar activity output
|
||||
.PP
|
||||
\fBactivity-calendar\fR outputs a visual grid of commit activity for a selected author, grouped by day-of-week (rows: Mon..Sun) and month (columns: Jan..Dec). Each cell is 3 characters wide, separated by one space.
|
||||
.PP
|
||||
Sample output:
|
||||
.PP
|
||||
.nf
|
||||
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
|
||||
Mon ▓▓▓ ░░░ ▒▒▒ ░░░ ░░░ ▒▒▒ ▓▓▓ ░░░ ░░░ ▓▓▓ ▒▒▒ ▒▒▒
|
||||
Tue ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ▒▒▒ ░░░ ░░░ ░░░
|
||||
Wed ░░░ ▓▓▓ ░░░ ▓▓▓ ▒▒▒ ░░░ ░░░ ▒▒▒ ░░░ ░░░ ▓▓▓ ░░░
|
||||
Thu ░░░ ▒▒▒ ░░░ ░░░ ▒▒▒ ░░░ ▓▓▓ ▒▒▒ ▒▒▒ ░░░ ░░░ ▒▒▒
|
||||
Fri ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ░░░ ▓▓▓ ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ░░░
|
||||
Sat ░░░ ░░░ ▒▒▒ ░░░ ░░░ ░░░ ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ▒▒▒ ░░░
|
||||
Sun ▓▓▓ ░░░ ▓▓▓ ░░░ ░░░ ▓▓▓ ░░░ ▒▒▒ ░░░ ░░░ ▓▓▓ ░░░
|
||||
|
||||
Legend: ... = 0 ░░░ = 1–2 ▒▒▒ = 3–5 ▓▓▓ = 6+ commits
|
||||
.PP
|
||||
You can set _GIT_IGNORE_AUTHORS to filter out specific authors, example:
|
||||
.PP
|
||||
.B export _GIT_IGNORE_AUTHORS="(author@examle.com|username)"
|
||||
.
|
||||
.fi
|
||||
|
||||
.PP
|
||||
.SH SEE ALSO
|
||||
.BR git (1)
|
||||
.PP
|
||||
Project homepage:
|
||||
.UR https://github.com/git-quick-stats/git-quick-stats
|
||||
.UE
|
||||
@@ -79,7 +79,7 @@ assert_end() {
|
||||
tests_endtime="$(date +%s%N)"
|
||||
# required visible decimal place for seconds (leading zeros if needed)
|
||||
local tests_time="$( \
|
||||
printf "%010d" "$(( ${tests_endtime/%N/000000000}
|
||||
printf "%010d" "$(( ${tests_endtime/%N/000000000}
|
||||
- ${tests_starttime/%N/000000000} ))")" # in ns
|
||||
tests="$tests_ran ${*:+$* }tests"
|
||||
[[ -n "$DISCOVERONLY" ]] && echo "collected $tests." && _assert_reset && return
|
||||
@@ -105,7 +105,7 @@ assert_end() {
|
||||
assert() {
|
||||
# assert <command> <expected stdout> [stdin]
|
||||
(( tests_ran++ )) || :
|
||||
[[ -z "$DISCOVERONLY" ]] || return
|
||||
[[ -z "$DISCOVERONLY" ]] || return 0
|
||||
expected=$(echo -ne "${2:-}")
|
||||
result="$(eval 2>/dev/null $1 <<< ${3:-})" || true
|
||||
if [[ "$result" == "$expected" ]]; then
|
||||
@@ -115,13 +115,13 @@ assert() {
|
||||
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
|
||||
[[ -z "$result" ]] && result="nothing" || result="\"$result\""
|
||||
[[ -z "$2" ]] && expected="nothing" || expected="\"$2\""
|
||||
_assert_fail "expected $expected${_indent}got $result" "$1" "$3"
|
||||
_assert_fail "expected $expected${_indent}got $result" "$1" "${3:-}"
|
||||
}
|
||||
|
||||
assert_raises() {
|
||||
# assert_raises <command> <expected code> [stdin]
|
||||
(( tests_ran++ )) || :
|
||||
[[ -z "$DISCOVERONLY" ]] || return
|
||||
[[ -z "$DISCOVERONLY" ]] || return 0
|
||||
status=0
|
||||
(eval $1 <<< ${3:-}) > /dev/null 2>&1 || status=$?
|
||||
expected=${2:-0}
|
||||
@@ -129,7 +129,12 @@ assert_raises() {
|
||||
[[ -z "$DEBUG" ]] || echo -n .
|
||||
return
|
||||
fi
|
||||
_assert_fail "program terminated with code $status instead of $expected" "$1" "$3"
|
||||
_assert_fail "program terminated with code $status instead of $expected" "$1" "${3:-}"
|
||||
}
|
||||
|
||||
assert_success() {
|
||||
# assert_success <command>
|
||||
assert_raises "$1" 0
|
||||
}
|
||||
|
||||
# _assert_with_grep <grep modifiers> <command> <expected output...>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Verify we are in a git repo. Create one if not
|
||||
# FIXME: All the paths are hardcoded currently and will break if anything
|
||||
# in this chain moves or gets executed elsewhere. Adjust all of these so
|
||||
# pathing does not matter as much such as creating a TOP variable that
|
||||
# does something like TOP=$(cd "$(dirname "$0")" || exit ; pwd -P)
|
||||
# or maybe leverages Make to handle these as test targets
|
||||
./tests/test-git/resetgit
|
||||
|
||||
. tests/assert.sh -v
|
||||
|
||||
src="./git-quick-stats"
|
||||
@@ -42,14 +50,20 @@ LIST OPTIONS
|
||||
show branches by date
|
||||
-C, --contributors
|
||||
see a list of everyone who contributed to the repo
|
||||
-n, --new-contributors
|
||||
list everyone who made their first contribution since a specified date
|
||||
-a, --commits-per-author
|
||||
displays a list of commits per author
|
||||
-d, --commits-per-day
|
||||
displays a list of commits per day
|
||||
-m, --commits-by-month
|
||||
displays a list of commits per month
|
||||
-Y, --commits-by-year
|
||||
displays a list of commits per year
|
||||
-w, --commits-by-weekday
|
||||
displays a list of commits per weekday
|
||||
-W, --commits-by-author-by-weekday
|
||||
displays a list of commits per weekday by author
|
||||
-o, --commits-by-hour
|
||||
displays a list of commits per hour
|
||||
-A, --commits-by-author-by-hour
|
||||
@@ -81,17 +95,26 @@ ADDITIONAL USAGE
|
||||
You can set _MENU_THEME to display the legacy color scheme
|
||||
ex: export _MENU_THEME=legacy
|
||||
You can set _GIT_BRANCH to set the branch of the stats
|
||||
ex: export _GIT_BRANCH=master"
|
||||
ex: export _GIT_BRANCH=master
|
||||
You can set _GIT_IGNORE_AUTHORS to filter out specific authors
|
||||
ex: export _GIT_IGNORE_AUTHORS=\"(author1|author2)\""
|
||||
|
||||
assert_raises "$src fail" 1
|
||||
|
||||
assert_contains "$src --suggest-reviewers" "Suggested code reviewers (based on git history)"
|
||||
assert_raises "$src --suggest-reviewers" 0
|
||||
assert_success "$src --suggest-reviewers"
|
||||
|
||||
assert_contains "$src --detailed-git-stats" "Contribution stats"
|
||||
assert_raises "$src --detailed-git-stats" 0
|
||||
assert_success "$src --detailed-git-stats"
|
||||
|
||||
assert_contains "$src --commits-per-day" "Git commits per date"
|
||||
assert_raises "$src --commits-per-day" 0
|
||||
assert_success "$src --commits-per-day"
|
||||
|
||||
assert_startswith "$src --commits-by-year" "Git commits by year"
|
||||
assert_success "$src --commits-by-year"
|
||||
|
||||
export LC_TIME=POSIX
|
||||
assert_startswith "$src --commits-by-year" "Git commits by year"
|
||||
assert_success "$src --commits-by-year"
|
||||
|
||||
assert_end
|
||||
|
||||
16
tests/test-git/resetgit
Executable file
16
tests/test-git/resetgit
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# Initialises a new local Git repo for test purpose if one does not exist already
|
||||
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
{
|
||||
git init
|
||||
git config user.name "$(printf %s 'Test Git,\nfor test purpose')"
|
||||
git config user.email "TestGit\o/@example.org"
|
||||
|
||||
printf 'test-git\n========\n' > README.md
|
||||
git add README.md
|
||||
git commit -m 'added readme (o\w/o)' -m 'in markdown, no \r\n, only \n' -m 'a very "simple" readme'
|
||||
testChars="$(printf 'tab [%b] form feed [%b] line feed [%b] carriage return [%b]' '\x09' '\x0C' '\x0A' '\x0D')"
|
||||
git notes add -m 'Some notes' -m 'out of ascii: été au cœur' -m "$testChars"
|
||||
git log
|
||||
} >/dev/null 2>&1
|
||||
fi
|
||||
Reference in New Issue
Block a user