From 7b9fbc43891800b6132d37b3f103713841aafbd0 Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 1 Nov 2019 17:31:14 +0800 Subject: [PATCH 1/3] git-standup: add option '-B' to group the commits by branch --- bin/git-standup | 33 ++++++++++++++++++++++++++++----- etc/git-extras-completion.zsh | 3 ++- man/git-standup.1 | 34 ++++++++++++++++++++++++++++++++-- man/git-standup.html | 23 +++++++++++++++++++++-- man/git-standup.md | 19 ++++++++++++++++++- 5 files changed, 101 insertions(+), 11 deletions(-) diff --git a/bin/git-standup b/bin/git-standup index 2de7601..55c0a8e 100755 --- a/bin/git-standup +++ b/bin/git-standup @@ -5,7 +5,7 @@ usage() { cat <] [-w ] [-d ] [-m ] [-g] [-h] [-f] + git standup [-a ] [-w ] [-d ] [-m ] [-g] [-h] [-f] [-B] -a - Specify author to restrict search to -w - Specify weekday range to limit search to @@ -16,6 +16,7 @@ usage() { -h - Display this help screen -g - Show if commit is GPG signed (G) or not (N) -f - Fetch the latest commits beforehand + -B - Display the commits in branch groups Examples: git standup -a "John Doe" -w "MON-FRI" -m 3 @@ -60,7 +61,7 @@ fi # which may fail on systems lacking tput or terminfo set -e -while getopts "hgfd:a:w:m:D:L" opt; do +while getopts "hgfBd:a:w:m:D:L" opt; do case $opt in h) usage @@ -119,6 +120,9 @@ while getopts "hgfd:a:w:m:D:L" opt; do g) GIT_PRETTY_FORMAT="%C(yellow)gpg: %G?%Creset" ;; + B) + GROUP_BY_BRANCHES=true + ;; \?) usage exit 1 @@ -148,7 +152,6 @@ GIT_PRETTY_FORMAT="%Cred%h%Creset - %s %Cgreen(%cd) %C(bold blue)<%an>%Creset $G GIT_DATE_FORMAT=${GIT_DATE_FORMAT:=relative} GIT_LOG_COMMAND="git --no-pager log \ - --all --no-merges --since \"$SINCE\" --until \"$UNTIL\" @@ -159,6 +162,26 @@ GIT_LOG_COMMAND="git --no-pager log \ --pretty=format:'$GIT_PRETTY_FORMAT' --date='$GIT_DATE_FORMAT'" +git_output() { + if [ "$GROUP_BY_BRANCHES" = true ]; then + local branches + branches=$(git branch --sort=-committerdate | awk '{print substr($0, 3)}') + for branch in $branches; do + # shellcheck disable=SC2086 + if output=$(eval $GIT_LOG_COMMAND "$branch"); then + if [[ ! -z "$output" ]] ; then + echo "${GREEN}${branch}${NORMAL}" + echo "$output" + fi + fi + # TODO optimize:return if the latest commit of a branch is eariler than the 'since' day + done + else + # shellcheck disable=SC2086 + eval $GIT_LOG_COMMAND --all + fi +} + ## For when the command has been run in a non-repo directory if [[ $in_git_repo != 0 ]]; then ## Set delimiter to newline for the loop @@ -191,7 +214,7 @@ if [[ $in_git_repo != 0 ]]; then pushd "$DIR" > /dev/null ## Show the detail only if it is a git repository if [[ -d ".git" || -f ".git" ]] ; then - if GITOUT=$(eval ${GIT_LOG_COMMAND}); then + if GITOUT=$(git_output); then ## Only output if there is some activities if [[ ! -z "$GITOUT" ]] ; then echo "${BOLD}${UNDERLINE}${YELLOW}$(basename "$DIR")${NORMAL}" @@ -209,7 +232,7 @@ else git fetch --all > /dev/null 2>&1 fi - if GITOUT=$(eval ${GIT_LOG_COMMAND}); then + if GITOUT=$(git_output); then if [[ ! -z "$GITOUT" ]] ; then echo "$GITOUT" else diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 6a078f2..b05e0cb 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -418,7 +418,8 @@ _git-standup() { '-g[Display GPG signed info]' \ '-h[Display help message]' \ '-L[Enable the inclusion of symbolic links]' \ - '-m[The depth of recursive directory search]' + '-m[The depth of recursive directory search]' \ + '-B[Display the commits in branch groups]' } _git-summary() { diff --git a/man/git-standup.1 b/man/git-standup.1 index 8fa4b01..7ea25aa 100644 --- a/man/git-standup.1 +++ b/man/git-standup.1 @@ -1,13 +1,13 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-STANDUP" "1" "October 2017" "" "Git Extras" +.TH "GIT\-STANDUP" "1" "November 2019" "" "Git Extras" . .SH "NAME" \fBgit\-standup\fR \- Recall the commit history . .SH "SYNOPSIS" -\fBgit\-standup\fR [\-a author] [\-m depth] [\-d days ago] [\-D date format] [\-g] [\-L] [\-f] +\fBgit\-standup\fR [\-a author] [\-m depth] [\-d days ago] [\-D date format] [\-g] [\-L] [\-f] [\-B] . .P \fBgit\-standup\fR \-h @@ -66,6 +66,12 @@ Fetch the latest commits before showing commit history\. .P The former version of \fBgit standup\fR accepted \fB \fR as options\. This interface is deprecated now, and please avoid to use it! . +.P +\-B +. +.P +Display the commits in branch groups\. +. .SH "EXAMPLES" This shows your commits since yesterday: . @@ -120,6 +126,30 @@ someProject/ . .IP "" 0 . +.P +By specifying the \fB\-B\fR option, git\-standuo will group the commits in branches: +. +.IP "" 4 +. +.nf + +$ git standup \-B \-a spacewander \-d 7 + +git\-summary\-cleanup +f788c78 \- git\-summary: clean up other shellcheck warnings (23 hours ago) +3e8c3ab \- git\-summary: fix incorrect active days when commits range is given (23 hours ago) +ff991ac \- git\-summary: remove useless result function\. (23 hours ago) +203f5b4 \- git\-summary: add \-\-dedup\-by\-email to remove duplicate users (5 days ago) +master +203f5b4 \- git\-summary: add \-\-dedup\-by\-email to remove duplicate users (5 days ago) +. +.fi +. +.IP "" 0 +. +.P +Note that the same commit can be seen in different branches\. +. .SH "AUTHOR" Originally from https://github\.com/kamranahmedse/git\-standup . diff --git a/man/git-standup.html b/man/git-standup.html index 88651f5..9407984 100644 --- a/man/git-standup.html +++ b/man/git-standup.html @@ -76,7 +76,7 @@

SYNOPSIS

-

git-standup [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f]

+

git-standup [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] [-B]

git-standup -h

@@ -122,6 +122,10 @@ Defaults to $(git config user.name).

The former version of git standup accepted <author> <since> <until> as options. This interface is deprecated now, and please avoid to use it!

+

-B

+ +

Display the commits in branch groups.

+

EXAMPLES

This shows your commits since yesterday:

@@ -154,6 +158,21 @@ someProject/ 46fef1d - use tinyXML to configure (7 days ago) <spacewander> +

By specifying the -B option, git-standuo will group the commits in branches:

+ +
$ git standup -B -a spacewander -d 7
+
+git-summary-cleanup
+f788c78 - git-summary: clean up other shellcheck warnings (23 hours ago) <spacewander>
+3e8c3ab - git-summary: fix incorrect active days when commits range is given (23 hours ago) <spacewander>
+ff991ac - git-summary: remove useless result function. (23 hours ago) <spacewander>
+203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) <spacewander>
+master
+203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) <spacewander>
+
+ +

Note that the same commit can be seen in different branches.

+

AUTHOR

Originally from https://github.com/kamranahmedse/git-standup

@@ -169,7 +188,7 @@ someProject/
  1. -
  2. October 2017
  3. +
  4. November 2019
  5. git-standup(1)
diff --git a/man/git-standup.md b/man/git-standup.md index 8f70567..fe2dec4 100644 --- a/man/git-standup.md +++ b/man/git-standup.md @@ -3,7 +3,7 @@ git-standup(1) -- Recall the commit history ## SYNOPSIS -`git-standup` [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] +`git-standup` [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] [-B] `git-standup` -h @@ -49,6 +49,10 @@ Fetch the latest commits before showing commit history. The former version of `git standup` accepted ` ` as options. This interface is deprecated now, and please avoid to use it! +-B + +Display the commits in branch groups. + ## EXAMPLES This shows your commits since yesterday: @@ -78,6 +82,19 @@ If current directory is not a git repo, git-standup will fetch data from all top 8e4182a - add watermark.png (7 days ago) 46fef1d - use tinyXML to configure (7 days ago) +By specifying the `-B` option, git-standuo will group the commits in branches: + + $ git standup -B -a spacewander -d 7 + + git-summary-cleanup + f788c78 - git-summary: clean up other shellcheck warnings (23 hours ago) + 3e8c3ab - git-summary: fix incorrect active days when commits range is given (23 hours ago) + ff991ac - git-summary: remove useless result function. (23 hours ago) + 203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) + master + 203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) + +Note that the same commit can be seen in different branches. ## AUTHOR From 227c19bb67431899311b752c619c80d6613e6a80 Mon Sep 17 00:00:00 2001 From: spacewander Date: Sun, 3 Nov 2019 10:49:21 +0800 Subject: [PATCH 2/3] git-standup: add separate newline between the output --- bin/git-standup | 2 ++ man/git-standup.1 | 1 + man/git-standup.html | 1 + man/git-standup.md | 1 + 4 files changed, 5 insertions(+) diff --git a/bin/git-standup b/bin/git-standup index 55c0a8e..538ae0b 100755 --- a/bin/git-standup +++ b/bin/git-standup @@ -172,6 +172,7 @@ git_output() { if [[ ! -z "$output" ]] ; then echo "${GREEN}${branch}${NORMAL}" echo "$output" + echo "" fi fi # TODO optimize:return if the latest commit of a branch is eariler than the 'since' day @@ -219,6 +220,7 @@ if [[ $in_git_repo != 0 ]]; then if [[ ! -z "$GITOUT" ]] ; then echo "${BOLD}${UNDERLINE}${YELLOW}$(basename "$DIR")${NORMAL}" echo "$GITOUT" + echo "" fi else echo "Repository under $DIR could not be queried." >&2 diff --git a/man/git-standup.1 b/man/git-standup.1 index 7ea25aa..98ad55e 100644 --- a/man/git-standup.1 +++ b/man/git-standup.1 @@ -140,6 +140,7 @@ f788c78 \- git\-summary: clean up other shellcheck warnings (23 hours ago) ff991ac \- git\-summary: remove useless result function\. (23 hours ago) 203f5b4 \- git\-summary: add \-\-dedup\-by\-email to remove duplicate users (5 days ago) + master 203f5b4 \- git\-summary: add \-\-dedup\-by\-email to remove duplicate users (5 days ago) . diff --git a/man/git-standup.html b/man/git-standup.html index 9407984..6fc9320 100644 --- a/man/git-standup.html +++ b/man/git-standup.html @@ -167,6 +167,7 @@ f788c78 - git-summary: clean up other shellcheck warnings (23 hours ago) <spa 3e8c3ab - git-summary: fix incorrect active days when commits range is given (23 hours ago) <spacewander> ff991ac - git-summary: remove useless result function. (23 hours ago) <spacewander> 203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) <spacewander> + master 203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) <spacewander> diff --git a/man/git-standup.md b/man/git-standup.md index fe2dec4..094742f 100644 --- a/man/git-standup.md +++ b/man/git-standup.md @@ -91,6 +91,7 @@ By specifying the `-B` option, git-standuo will group the commits in branches: 3e8c3ab - git-summary: fix incorrect active days when commits range is given (23 hours ago) ff991ac - git-summary: remove useless result function. (23 hours ago) 203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) + master 203f5b4 - git-summary: add --dedup-by-email to remove duplicate users (5 days ago) From 952d1eb76f7bafbbee9fbc2c7dd5201c0f6b459a Mon Sep 17 00:00:00 2001 From: spacewander Date: Mon, 4 Nov 2019 11:36:29 +0800 Subject: [PATCH 3/3] git-standup: add option to limit the number of commit --- bin/git-standup | 11 +++++++++-- man/git-standup.1 | 8 +++++++- man/git-standup.html | 12 +++++++++++- man/git-standup.md | 12 +++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/bin/git-standup b/bin/git-standup index 538ae0b..9a0c636 100755 --- a/bin/git-standup +++ b/bin/git-standup @@ -5,7 +5,7 @@ usage() { cat <] [-w ] [-d ] [-m ] [-g] [-h] [-f] [-B] + git standup [-a ] [-w ] [-d ] [-m ] [-g] [-h] [-f] [-B] [-n \fR .P Display the commits in branch groups\. . +.P +\-n number\-of\-commits +. +.P +Limit the number of commits displayed per group\. By default, the limitation is applied in the repository level\. For example, if you have 3 repositories under the current directory, \fBgit standup \.\.\. \-n 1\fR will show you 3 commits at most\. When \fB\-B\fR is specific, the limitation is applied in the branch level\. For instance, if each of your 3 repositories have 2 branches, \fBgit standup \.\.\. \-B \-n 1\fR will display 6 commits at most\. +. .SH "EXAMPLES" This shows your commits since yesterday: . diff --git a/man/git-standup.html b/man/git-standup.html index 6fc9320..116e9c6 100644 --- a/man/git-standup.html +++ b/man/git-standup.html @@ -76,7 +76,7 @@

SYNOPSIS

-

git-standup [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] [-B]

+

git-standup [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] [-B] [-n number of commits]

git-standup -h

@@ -126,6 +126,16 @@ This interface is deprecated now, and please avoid to use it!

Display the commits in branch groups.

+

-n number-of-commits

+ +

Limit the number of commits displayed per group. +By default, the limitation is applied in the repository level. For example, if you +have 3 repositories under the current directory, git standup ... -n 1 will +show you 3 commits at most. +When -B is specific, the limitation is applied in the branch level. For instance, +if each of your 3 repositories have 2 branches, git standup ... -B -n 1 will +display 6 commits at most.

+

EXAMPLES

This shows your commits since yesterday:

diff --git a/man/git-standup.md b/man/git-standup.md index 094742f..671ab77 100644 --- a/man/git-standup.md +++ b/man/git-standup.md @@ -3,7 +3,7 @@ git-standup(1) -- Recall the commit history ## SYNOPSIS -`git-standup` [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] [-B] +`git-standup` [-a author] [-m depth] [-d days ago] [-D date format] [-g] [-L] [-f] [-B] [-n number of commits] `git-standup` -h @@ -53,6 +53,16 @@ This interface is deprecated now, and please avoid to use it! Display the commits in branch groups. +-n number-of-commits + +Limit the number of commits displayed per group. +By default, the limitation is applied in the repository level. For example, if you +have 3 repositories under the current directory, `git standup ... -n 1` will +show you 3 commits at most. +When `-B` is specific, the limitation is applied in the branch level. For instance, +if each of your 3 repositories have 2 branches, `git standup ... -B -n 1` will +display 6 commits at most. + ## EXAMPLES This shows your commits since yesterday: