diff --git a/Commands.md b/Commands.md index 1ae01bb..cba10d3 100644 --- a/Commands.md +++ b/Commands.md @@ -56,6 +56,7 @@ - [`git show-merged-branches`](#git-show-merged-branches) - [`git show-tree`](#git-show-tree) - [`git show-unmerged-branches`](#git-show-unmerged-branches) + - [`git stamp`](#git-stamp) - [`git squash`](#git-squash) - [`git standup`](#git-standup) - [`git summary`](#git-summary) @@ -958,6 +959,79 @@ For example, running `git show-tree` will display: Be free to try it for yourself! + +## git stamp + +Stamp the last commit message + +Commit message is + +```bash +Fix timezone bug +``` + +Reference the issues numbers from your bug tracker + +```bash +$ git stamp Issue FOO-123 + +commit 787590e42c9bacd249f3b79faee7aecdc9de28ec +Author: Jack +Commit: Jack + + Fix timezone bug + + Issue FOO-123 + +$ git stamp Issue FOO-456 \#close + +commit f8d920511e052bea39ce2088d1d723b475aeff87 +Author: Jack +Commit: Jack + + Fix timezone bug + + Issue FOO-123 + + Issue FOO-456 #close +``` + +Link to its review page + +```bash +$ git stamp Review https://reviews.foo.org/r/4567/ + +commit 6c6bcf43bd32a76e37b6fc9708d3ff0ae723c7da +Author: Jack +Commit: Jack + + Fix timezone bug + + Issue FOO-123 + + Issue FOO-456 #close + + Review https://reviews.foo.org/r/4567/ +``` + +Replace previous issues with a new one +(Note that the identifier is case insensitive) + +```bash +$ git stamp --replace issue BAR-123 + +commit 2b93c56b2340578cc3478008e2cadb05a7bcccfa +Author: Jack +Commit: Jack + + Fix timezone bug + + Review https://reviews.foo.org/r/4567/ + + issue BAR-123 +``` + + ## git standup Recall what you did or find what someone else did in a given range of time. diff --git a/bin/git-stamp b/bin/git-stamp new file mode 100755 index 0000000..84fbd62 --- /dev/null +++ b/bin/git-stamp @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + + +init_variables() { + COMMAND=${0#*-} + + REPLACE=false + unset ID + unset MSG +} + + +usage() { + cat << EOF +usage: git ${COMMAND} [] [] + +Options: + -r, --replace replace all previous stamps with same id +EOF +} + + +error() { + if [[ -n "$1" ]]; then + local msg=$( echo "error: $1" ) + echo -e "${msg}" >&2 + fi + usage + exit 1 +} + + +stamp() { + local commit_msg=$( git log -1 --pretty=%B ) + local stamp_msg + [[ -n "${MSG}" ]] && stamp_msg="${ID} ${MSG}" || stamp_msg="${ID}" + + if ${REPLACE}; then + # remove previous stamps with same ID from the commit message + commit_msg=$( + echo "${commit_msg}" \ + | grep --ignore-case --invert-match "^${ID}\b" \ + | cat --squeeze-blank + ) + fi + + # append the stamp to the commit message in a new paragraph + git commit --amend \ + --message "${commit_msg}" \ + --message "${stamp_msg}" \ + > /dev/null + + # show result + git log -1 --pretty=full +} + + +parse_options() { + while [[ "$#" -gt 0 ]]; do + case "$1" in + -h) + usage + exit 0 + ;; + --replace|-r) + REPLACE=true + shift + ;; + *) + break + ;; + esac + done + + ID="$1" + MSG="${@:2}" +} + + +validate_options() { + # ID should be set to non-empty string + if [[ -z "${ID}" ]]; then + error "missing stamp identifier" + fi +} + + +init_variables +parse_options "$@" +validate_options + +stamp \ No newline at end of file diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index ce404ca..a28d3f3 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -134,6 +134,10 @@ _git_scp(){ __git_complete_remote_or_refspec } +_git_stamp(){ + __gitcomp '--replace -r' +} + _git_rscp(){ __git_complete_remote_or_refspec } diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 09be7a1..5bb7245 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -337,6 +337,10 @@ _git-squash() { ':branch-name:__gitex_branch_names' } +_git-stamp() { + _arguments -C \ + '(--replace -r)'{--replace,-r}'[replace stamps with same id]' +} _git-summary() { _arguments '--line[summarize with lines rather than commits]' @@ -407,6 +411,7 @@ zstyle ':completion:*:*:git:*' user-commands \ show-tree:'show branch tree of commit history' \ show-unmerged-branches:'show unmerged branches' \ squash:'import changes from a branch' \ + stamp:'stamp the last commit message' \ standup:'recall the commit history' \ summary:'show repository summary' \ sync:'sync local branch with remote branch' \ diff --git a/man/git-stamp.1 b/man/git-stamp.1 new file mode 100644 index 0000000..3c4d8b2 --- /dev/null +++ b/man/git-stamp.1 @@ -0,0 +1,127 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-STAMP" "1" "October 2016" "" "" +. +.SH "NAME" +\fBgit\-stamp\fR \- Stamp the last commit message +. +.SH "SYNOPSIS" +\fBgit stamp [] []\fR +. +.SH "DESCRIPTION" +Lets you amend the last commit with a stamp message\. +. +.P +The command appends a message with its identifier to the last commit message\. +. +.br +By default all stamps are appended as a new paragraph to the commit message\. +. +.br +You can change this behavior by using the \-\-replace flag\. +. +.br +With this flag, all the related stamps with the same identifier will be removed first before the new one gets appended\. +. +.P +\fBWARNING!\fR If a commit message without stamp have a line starting with the same identifier, it will be interpreted as a stamp +. +.SH "OPTIONS" +\-r, \-\-replace +. +.IP "" 4 +. +.nf + +Replace all previous stamps in the last commit message that have the same identifier +The identifier is case insensitive for this replacement +. +.fi +. +.IP "" 0 +. +.SH "EXAMPLES" +Commit message is +. +.IP "" 4 +. +.nf + +| Fix timezone bug +. +.fi +. +.IP "" 0 +. +.P +Reference the issues numbers from your bug tracker +. +.IP "" 4 +. +.nf + +$ git stamp Issue FOO\-123 +$ git stamp Issue FOO\-456 \e#close + +| Fix timezone bug +| +| Issue FOO\-123 +| +| Issue FOO\-456 #close +. +.fi +. +.IP "" 0 +. +.P +Link to its review page +. +.IP "" 4 +. +.nf + +$ git stamp Review https://reviews\.foo\.org/r/4567/ + +| Fix timezone bug +| +| Issue FOO\-123 +| +| Issue FOO\-456 #close +| +| Review https://reviews\.foo\.org/r/4567/ +. +.fi +. +.IP "" 0 +. +.P +Replace previous issues with a new one +. +.br +(Note that the identifier is case insensitive) +. +.IP "" 4 +. +.nf + +$ git stamp \-\-replace issue BAR\-123 + +| Fix timezone bug +| +| Review https://reviews\.foo\.org/r/4567/ +| +| issue BAR\-123 +. +.fi +. +.IP "" 0 +. +.SH "AUTHOR" +Written by Damien Tardy\-Panis <\fIdamien@tardypad\.me\fR> +. +.SH "REPORTING BUGS" +<\fIhttp://github\.com/tj/git\-extras/issues\fR> +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-stamp.html b/man/git-stamp.html new file mode 100644 index 0000000..f443963 --- /dev/null +++ b/man/git-stamp.html @@ -0,0 +1,165 @@ + + + + + + git-stamp(1) - Stamp the last commit message + + + + +
+ + + +
    +
  1. git-stamp(1)
  2. +
  3. +
  4. git-stamp(1)
  5. +
+ +

NAME

+

+ git-stamp - Stamp the last commit message +

+ +

SYNOPSIS

+ +

git stamp [<options>] <id> [<messages>]

+ +

DESCRIPTION

+ +

Lets you amend the last commit with a stamp message.

+ +

The command appends a message with its identifier to the last commit message.
+By default all stamps are appended as a new paragraph to the commit message.
+You can change this behavior by using the --replace flag.
+With this flag, all the related stamps with the same identifier will be removed first before the new one gets appended.

+ +

WARNING! If a commit message without stamp have a line starting with the same identifier, it will be interpreted as a stamp

+ +

OPTIONS

+ +

-r, --replace

+ +
Replace all previous stamps in the last commit message that have the same identifier  
+The identifier is case insensitive for this replacement
+
+ +

EXAMPLES

+ +

Commit message is

+ +
| Fix timezone bug
+
+ +

Reference the issues numbers from your bug tracker

+ +
$ git stamp Issue FOO-123
+$ git stamp Issue FOO-456 \#close
+
+| Fix timezone bug
+|
+| Issue FOO-123
+|
+| Issue FOO-456 #close
+
+ +

Link to its review page

+ +
$ git stamp Review https://reviews.foo.org/r/4567/
+
+| Fix timezone bug
+|
+| Issue FOO-123
+|
+| Issue FOO-456 #close
+|
+| Review https://reviews.foo.org/r/4567/
+
+ +

Replace previous issues with a new one
+(Note that the identifier is case insensitive)

+ +
$ git stamp --replace issue BAR-123
+
+| Fix timezone bug
+|
+| Review https://reviews.foo.org/r/4567/
+|
+| issue BAR-123
+
+ +

AUTHOR

+ +

Written by Damien Tardy-Panis <damien@tardypad.me>

+ +

REPORTING BUGS

+ +

<http://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. October 2016
  3. +
  4. git-stamp(1)
  5. +
+ +
+ + diff --git a/man/git-stamp.md b/man/git-stamp.md new file mode 100644 index 0000000..da97c68 --- /dev/null +++ b/man/git-stamp.md @@ -0,0 +1,76 @@ +git-stamp(1) -- Stamp the last commit message +============================================= + +## SYNOPSIS + +`git stamp [] []` + +## DESCRIPTION + +Lets you amend the last commit with a stamp message. + +The command appends a message with its identifier to the last commit message. +By default all stamps are appended as a new paragraph to the commit message. +You can change this behavior by using the --replace flag. +With this flag, all the related stamps with the same identifier will be removed first before the new one gets appended. + +`WARNING!` If a commit message without stamp have a line starting with the same identifier, it will be interpreted as a stamp + +## OPTIONS + + -r, --replace + + Replace all previous stamps in the last commit message that have the same identifier + The identifier is case insensitive for this replacement + +## EXAMPLES + +Commit message is + + | Fix timezone bug + +Reference the issues numbers from your bug tracker + + $ git stamp Issue FOO-123 + $ git stamp Issue FOO-456 \#close + + | Fix timezone bug + | + | Issue FOO-123 + | + | Issue FOO-456 #close + +Link to its review page + + $ git stamp Review https://reviews.foo.org/r/4567/ + + | Fix timezone bug + | + | Issue FOO-123 + | + | Issue FOO-456 #close + | + | Review https://reviews.foo.org/r/4567/ + +Replace previous issues with a new one +(Note that the identifier is case insensitive) + + $ git stamp --replace issue BAR-123 + + | Fix timezone bug + | + | Review https://reviews.foo.org/r/4567/ + | + | issue BAR-123 + +## AUTHOR + +Written by Damien Tardy-Panis <> + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> diff --git a/man/index.txt b/man/index.txt index 304b50b..06b0363 100644 --- a/man/index.txt +++ b/man/index.txt @@ -51,6 +51,7 @@ git-show-merged-branches(1) git-show-merged-branches git-show-tree(1) git-show-tree git-show-unmerged-branches(1) git-show-unmerged-branches git-squash(1) git-squash +git-stamp(1) git-stamp git-summary(1) git-summary git-touch(1) git-touch git-undo(1) git-undo