Merge pull request #182 from sandr01d/gct

Implemented git checkout tag
This commit is contained in:
Wenxuan 2022-02-15 10:27:33 +08:00 committed by GitHub
commit e0d3552d45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -87,6 +87,8 @@ source (curl -sSL git.io/forgit-fish | psub)
- **Interactive `git checkout <branch>` selector** (`gcb`)
- **Interactive `git checkout <tag>` selector** (`gct`)
- **Interactive `git checkout <commit>` selector** (`gco`)
- **Interactive `git stash` viewer** (`gss`)
@ -136,6 +138,7 @@ forgit_reset_head=grh
forgit_ignore=gi
forgit_checkout_file=gcf
forgit_checkout_branch=gcb
forgit_checkout_tag=gct
forgit_checkout_commit=gco
forgit_clean=gclean
forgit_stash_show=gss
@ -215,6 +218,7 @@ Customizing fzf options for each command individually is also supported:
| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` |
| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` |
| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` |
| `gct` | `FORGIT_CHECKOUT_TAG_FZF_OPTS` |
| `gco` | `FORGIT_CHECKOUT_COMMIT_FZF_OPTS` |
| `gss` | `FORGIT_STASH_FZF_OPTS` |
| `gclean` | `FORGIT_CLEAN_FZF_OPTS` |

View file

@ -243,6 +243,23 @@ forgit::checkout::branch() {
fi
}
# git checkout-tag selector
forgit::checkout::tag() {
forgit::inside_work_tree || return 1
[[ $# -ne 0 ]] && { git checkout "$@"; return $?; }
local cmd opts preview
cmd="git tag -l --sort=-v:refname"
preview="git log {1} --graph --pretty=format:'$forgit_log_format' --color=always --abbrev-commit --date=relative"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m --tiebreak=index
$FORGIT_CHECKOUT_TAG_FZF_OPTS
"
tag="$(eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview")"
[[ -z "$tag" ]] && return 1
git checkout "$tag"
}
# git checkout-commit selector
forgit::checkout::commit() {
forgit::inside_work_tree || return 1
@ -335,6 +352,7 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then
alias "${forgit_checkout_file:-gcf}"='forgit::checkout::file'
alias "${forgit_checkout_branch:-gcb}"='forgit::checkout::branch'
alias "${forgit_checkout_commit:-gco}"='forgit::checkout::commit'
alias "${forgit_checkout_tag:-gct}"='forgit::checkout::tag'
alias "${forgit_clean:-gclean}"='forgit::clean'
alias "${forgit_stash_show:-gss}"='forgit::stash::show'
alias "${forgit_cherry_pick:-gcp}"='forgit::cherry::pick'