From 4efad7ab1ba0d1715af62e484c6852808581cfb9 Mon Sep 17 00:00:00 2001 From: Rejman Nascimento <72097727+rejmann@users.noreply.github.com> Date: Thu, 1 Feb 2024 12:54:24 -0300 Subject: feat(git-commit): add `wip` kind (#12188) --- plugins/git-commit/README.md | 4 +++- plugins/git-commit/git-commit.plugin.zsh | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md index 91cc73b44..a00983935 100644 --- a/plugins/git-commit/README.md +++ b/plugins/git-commit/README.md @@ -29,8 +29,9 @@ Where `type` is one of the following: - `rev` - `style` - `test` +- `wip` -> NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name. +> NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name. > It will still generate a commit message in the format `revert: ` ## Examples @@ -38,5 +39,6 @@ Where `type` is one of the following: | Git alias | Command | | --------------------------------------------- | ---------------------------------------------------- | | `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` | +| `git wip "work in progress"` | `git commit -m "work in progress"` | | `git fix -s "router" "correct redirect link"` | `git commit -m "fix(router): correct redirect link"` | | `git rev -s "api" "rollback v2"` | `git commit -m "revert(api): rollback v2"` | diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 72cecb1d6..3f0c2121d 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -11,6 +11,7 @@ _git_commit_aliases=( 'revert' 'style' 'test' + 'wip' ) local alias type -- cgit v1.2.3-70-g09d2 From e3216d15c2d2ee81716e4c2cbc999b4bed5694d9 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sat, 2 Mar 2024 00:57:26 +0100 Subject: fix(git-commit)!: allow alias update BREAKING CHANGE: Prior to this commit, git aliases were not being updated after every update of oh-my-zsh. In case you were using git-commit plugin before this commit, please remove your git aliases to proceed. --- plugins/git-commit/git-commit.plugin.zsh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 3f0c2121d..207c37e21 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -1,3 +1,8 @@ +if git config --global --get-all alias.$_alias >/dev/null 2>&1 \ + && ! git config --global --get-all oh-my-zsh.git-commit-alias >/dev/null 2>&1; then + return +fi + local -a _git_commit_aliases _git_commit_aliases=( 'build' @@ -14,19 +19,18 @@ _git_commit_aliases=( 'wip' ) -local alias type -for type in "${_git_commit_aliases[@]}"; do +local _alias _type +for _type in "${_git_commit_aliases[@]}"; do # an alias can't be named "revert" because the git command takes precedence # https://stackoverflow.com/a/3538791 - case "$type" in - revert) alias=rev ;; - *) alias=$type ;; + case "$_type" in + revert) _alias=rev ;; + *) _alias=$_type ;; esac - local func='!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$type'(${scope}): ${@}"; else git commit -m "'$type': ${@}"; fi }; a' - if ! git config --global --get-all alias.${alias} >/dev/null 2>&1; then - git config --global alias.${alias} "$func" - fi + local _func='!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$type'(${scope}): ${@}"; else git commit -m "'$type': ${@}"; fi }; a' + + git config --global alias.$_alias "$_func" done -unset _git_commit_aliases alias type func +git config --global oh-my-zsh.git-commit-alias "true" -- cgit v1.2.3-70-g09d2 From 3ee108ccb301dd4143080e8bfd8f9ae869957a2e Mon Sep 17 00:00:00 2001 From: Rejman Date: Sat, 2 Mar 2024 01:21:30 +0100 Subject: feat(git-commit): add `-a | --attention` flag Refactor function as well to reduce flaws and increase stability Closes #12234 Co-authored-by: Carlo Sala --- plugins/git-commit/git-commit.plugin.zsh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 207c37e21..7ad349735 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -28,7 +28,30 @@ for _type in "${_git_commit_aliases[@]}"; do *) _alias=$_type ;; esac - local _func='!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$type'(${scope}): ${@}"; else git commit -m "'$type': ${@}"; fi }; a' + local _func='!a() { +local _scope _attention _message +while [ $# -ne 0 ]; do +case $1 in + -s | --scope ) + if [ -z $2 ]; then + echo "Missing scope!" + return 1 + fi + _scope="$2" + shift 2 + ;; + -a | --attention ) + _attention="!" + shift 1 + ;; + * ) + _message+=" $1" + shift 1 + ;; +esac +done +git commit -m "'$_type'${_scope:+(${_scope})}${_attention}:${_message}" +}; a' git config --global alias.$_alias "$_func" done -- cgit v1.2.3-70-g09d2 From 8e088ded8289a9db2a9f2c03cab618d6dd017dd7 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sat, 2 Mar 2024 01:25:20 +0100 Subject: docs(git-commit): document attention flag --- plugins/git-commit/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md index a00983935..49072d0fb 100644 --- a/plugins/git-commit/README.md +++ b/plugins/git-commit/README.md @@ -11,7 +11,7 @@ plugins=(... git-commit) ## Syntax ```zsh -git [(-s, --scope) ""] "" +git [(-s, --scope) ""] [(-a, --attention)] "" ``` > ⚠️ Single/Double quotes around the scope and message are required -- cgit v1.2.3-70-g09d2 From b6c1de87b01aaf5eb434b86b1d32b92cb37467bb Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sat, 2 Mar 2024 10:05:44 +0100 Subject: fix(git-commit): add omz version check --- plugins/git-commit/git-commit.plugin.zsh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 7ad349735..121ae59de 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -1,7 +1,8 @@ -if git config --global --get-all alias.$_alias >/dev/null 2>&1 \ - && ! git config --global --get-all oh-my-zsh.git-commit-alias >/dev/null 2>&1; then +local _rev="$(git -C $ZSH rev-parse HEAD 2> /dev/null)" +if [[ $_rev == $(git config --global --get oh-my-zsh.git-commit-alias 2> /dev/null) ]]; then return fi +git config --global oh-my-zsh.git-commit-alias "$_rev" local -a _git_commit_aliases _git_commit_aliases=( @@ -55,5 +56,3 @@ git commit -m "'$_type'${_scope:+(${_scope})}${_attention}:${_message}" git config --global alias.$_alias "$_func" done - -git config --global oh-my-zsh.git-commit-alias "true" -- cgit v1.2.3-70-g09d2 From 458fc2e1df4757e64b036edee17ccdefdde41f73 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sat, 2 Mar 2024 10:05:54 +0100 Subject: docs(git-commit): add warning --- plugins/git-commit/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md index 49072d0fb..f812ee23f 100644 --- a/plugins/git-commit/README.md +++ b/plugins/git-commit/README.md @@ -1,6 +1,8 @@ # git-commit plugin -The git-commit plugin adds several [git aliases](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-alias) for [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) messages. +The git-commit plugin adds several +[git aliases](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-alias) for +[conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) messages. To use it, add `git-commit` to the plugins array in your zshrc file: @@ -14,8 +16,6 @@ plugins=(... git-commit) git [(-s, --scope) ""] [(-a, --attention)] "" ``` -> ⚠️ Single/Double quotes around the scope and message are required - Where `type` is one of the following: - `build` @@ -34,6 +34,9 @@ Where `type` is one of the following: > NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name. > It will still generate a commit message in the format `revert: ` +> ⚠️ Enabling this plugin will (potentially) overwrite all `alias.` that you manually set. Use with +> care! + ## Examples | Git alias | Command | -- cgit v1.2.3-70-g09d2 From 70395a64637ad1a94b11f6007f29ee0c0d716884 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sun, 3 Mar 2024 11:22:25 +0100 Subject: fix(git): do not use `+=` in sh script Fixes #12251 --- plugins/git-commit/git-commit.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/git-commit') diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh index 121ae59de..c4df77c80 100644 --- a/plugins/git-commit/git-commit.plugin.zsh +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -46,7 +46,7 @@ case $1 in shift 1 ;; * ) - _message+=" $1" + _message="${_message} $1" shift 1 ;; esac -- cgit v1.2.3-70-g09d2