mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
Merge pull request #190 from sandr01d/grc
Implemented git revert commit
This commit is contained in:
commit
c9185dda1a
|
|
@ -91,6 +91,8 @@ source (curl -sSL git.io/forgit-fish | psub)
|
|||
|
||||
- **Interactive `git checkout <commit>` selector** (`gco`)
|
||||
|
||||
- **Interactive `git revert <commit>` selector** (`grc`)
|
||||
|
||||
- **Interactive `git stash` viewer** (`gss`)
|
||||
|
||||
- **Interactive `git clean` selector** (`gclean`)
|
||||
|
|
@ -140,6 +142,7 @@ forgit_checkout_file=gcf
|
|||
forgit_checkout_branch=gcb
|
||||
forgit_checkout_tag=gct
|
||||
forgit_checkout_commit=gco
|
||||
forgit_revert_commit=grc
|
||||
forgit_clean=gclean
|
||||
forgit_stash_show=gss
|
||||
forgit_cherry_pick=gcp
|
||||
|
|
@ -220,6 +223,7 @@ Customizing fzf options for each command individually is also supported:
|
|||
| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` |
|
||||
| `gct` | `FORGIT_CHECKOUT_TAG_FZF_OPTS` |
|
||||
| `gco` | `FORGIT_CHECKOUT_COMMIT_FZF_OPTS` |
|
||||
| `grc` | `FORGIT_REVERT_COMMIT_OPTS` |
|
||||
| `gss` | `FORGIT_STASH_FZF_OPTS` |
|
||||
| `gclean` | `FORGIT_CLEAN_FZF_OPTS` |
|
||||
| `grb` | `FORGIT_REBASE_FZF_OPTS` |
|
||||
|
|
|
|||
|
|
@ -284,6 +284,28 @@ forgit::checkout::commit() {
|
|||
FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git checkout % --
|
||||
}
|
||||
|
||||
# git revert-commit selector
|
||||
forgit::revert::commit() {
|
||||
forgit::inside_work_tree || return 1
|
||||
[[ $# -ne 0 ]] && { git revert "$@"; return $?; }
|
||||
local cmd opts files preview commits
|
||||
cmd="git log --graph --color=always --format='$forgit_log_format' $* $forgit_emojify"
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
+s --tiebreak=index
|
||||
$FORGIT_REVERT_COMMIT_OPTS
|
||||
"
|
||||
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
|
||||
preview="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager"
|
||||
commits="$(eval "$cmd" |
|
||||
FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" -m |
|
||||
grep -Eo '^\*\s[a-f0-9]+' |
|
||||
cut -c 3- |
|
||||
tr $'\n' ' ')"
|
||||
[[ -z "$commits" ]] && return 1
|
||||
eval "git revert $commits"
|
||||
}
|
||||
|
||||
# git ignore generator
|
||||
export FORGIT_GI_REPO_REMOTE=${FORGIT_GI_REPO_REMOTE:-https://github.com/dvcs/gitignore}
|
||||
export FORGIT_GI_REPO_LOCAL="${FORGIT_GI_REPO_LOCAL:-${XDG_CACHE_HOME:-$HOME/.cache}/forgit/gi/repos/dvcs/gitignore}"
|
||||
|
|
@ -358,6 +380,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_revert_commit:-grc}"='forgit::revert::commit'
|
||||
alias "${forgit_checkout_tag:-gct}"='forgit::checkout::tag'
|
||||
alias "${forgit_clean:-gclean}"='forgit::clean'
|
||||
alias "${forgit_stash_show:-gss}"='forgit::stash::show'
|
||||
|
|
|
|||
Loading…
Reference in a new issue