1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 17:28:01 +00:00

git: Alias and function cleanup and formatting for clarity

Changes:
- Prefer longer form of git switch for better clarity.
- Move `-S` (`--gpg-sign`) in all the alias definitions to  the end to
  allow custom keyid.
- Simplify operations in helper functions git native calls.
- Apply minor reformatting and rearranging.
This commit is contained in:
Indrajit Raychaudhuri 2021-05-11 00:35:47 -05:00 committed by Indrajit Raychaudhuri
parent 9459a716bf
commit efebe3efec
4 changed files with 70 additions and 61 deletions

View File

@ -66,26 +66,26 @@ zstyle ':prezto:module:git:alias' skip 'yes'
### Commit (c) ### Commit (c)
- `gc` records changes to the repository. - `gc` records changes to the repository.
- `gca` stages all modified and deleted files.
- `gcm` records changes to the repository with the given message.
- `gcS` records changes to the repository. (Signed) - `gcS` records changes to the repository. (Signed)
- `gcSa` stages all modified and deleted files. (Signed) - `gca` stages all modified and deleted files.
- `gcSm` records changes to the repository with the given message. (Signed) - `gcaS` stages all modified and deleted files. (Signed)
- `gcm` records changes to the repository with the given message.
- `gcmS` records changes to the repository with the given message. (Signed)
- `gcam` stages all modified and deleted files, and records changes to the - `gcam` stages all modified and deleted files, and records changes to the
repository with the given message. repository with the given message.
- `gco` checks out a branch or paths to work tree. - `gco` checks out a branch or paths to work tree.
- `gcO` checks out hunks from the index or the tree interactively. - `gcO` checks out hunks from the index or the tree interactively.
- `gcf` amends the tip of the current branch using the same log message as - `gcf` amends the tip of the current branch using the same log message as
_HEAD_. _HEAD_.
- `gcSf` amends the tip of the current branch using the same log message as - `gcfS` amends the tip of the current branch using the same log message as
_HEAD_. (Signed) _HEAD_. (Signed)
- `gcF` amends the tip of the current branch. - `gcF` amends the tip of the current branch.
- `gcSF` amends the tip of the current branch. (Signed) - `gcFS` amends the tip of the current branch. (Signed)
- `gcp` applies changes introduced by existing commits. - `gcp` applies changes introduced by existing commits.
- `gcP` applies changes introduced by existing commits without committing. - `gcP` applies changes introduced by existing commits without committing.
- `gcr` reverts existing commits by reverting patches and recording new commits. - `gcr` reverts existing commits by reverting patches and recording new commits.
- `gcR` removes the _HEAD_ commit. - `gcR` removes the _HEAD_ commit.
- `gcs` displays various types of objects. - `gcs` displays commits with various objects.
- `gcsS` displays commits with GPG signature. - `gcsS` displays commits with GPG signature.
- `gcl` lists lost commits. - `gcl` lists lost commits.
- `gcy` displays commits yet to be applied to upstream in the short format. - `gcy` displays commits yet to be applied to upstream in the short format.

View File

@ -8,25 +8,24 @@
# #
# Settings # Settings
# #
#
# Log # Log
zstyle -s ':prezto:module:git:log:medium' format '_git_log_medium_format' \ zstyle -s ':prezto:module:git:log:medium' format '_git_log_medium_format' \
|| _git_log_medium_format='%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B' || _git_log_medium_format='%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B'
zstyle -s ':prezto:module:git:log:oneline' format '_git_log_oneline_format' \ zstyle -s ':prezto:module:git:log:oneline' format '_git_log_oneline_format' \
|| _git_log_oneline_format='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n' || _git_log_oneline_format='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n'
zstyle -s ':prezto:module:git:log:brief' format '_git_log_brief_format' \ zstyle -s ':prezto:module:git:log:brief' format '_git_log_brief_format' \
|| _git_log_brief_format='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n' || _git_log_brief_format='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n'
# Status # Status
zstyle -s ':prezto:module:git:status:ignore' submodules '_git_status_ignore_submodules' \ zstyle -s ':prezto:module:git:status:ignore' submodules '_git_status_ignore_submodules' \
|| _git_status_ignore_submodules='none' || _git_status_ignore_submodules='none'
# #
# Aliases # Aliases
# #
if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then if ! zstyle -t ':prezto:module:git:alias' skip; then
# Git # Git
alias g='git' alias g='git'
@ -51,18 +50,18 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then
# Commit (c) # Commit (c)
alias gc='git commit --verbose' alias gc='git commit --verbose'
alias gcS='git commit --verbose --gpg-sign'
alias gca='git commit --verbose --all' alias gca='git commit --verbose --all'
alias gcaS='git commit --verbose --all --gpg-sign'
alias gcm='git commit --message' alias gcm='git commit --message'
alias gcS='git commit -S --verbose' alias gcmS='git commit --message --gpg-sign'
alias gcSa='git commit -S --verbose --all'
alias gcSm='git commit -S --message'
alias gcam='git commit --all --message' alias gcam='git commit --all --message'
alias gco='git checkout' alias gco='git checkout'
alias gcO='git checkout --patch' alias gcO='git checkout --patch'
alias gcf='git commit --amend --reuse-message HEAD' alias gcf='git commit --amend --reuse-message HEAD'
alias gcSf='git commit -S --amend --reuse-message HEAD' alias gcfS='git commit --amend --reuse-message HEAD --gpg-sign'
alias gcF='git commit --verbose --amend' alias gcF='git commit --verbose --amend'
alias gcSF='git commit -S --verbose --amend' alias gcFS='git commit --verbose --amend --gpg-sign'
alias gcp='git cherry-pick --ff' alias gcp='git cherry-pick --ff'
alias gcP='git cherry-pick --no-commit' alias gcP='git cherry-pick --no-commit'
alias gcr='git revert' alias gcr='git revert'
@ -70,8 +69,8 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then
alias gcs='git show' alias gcs='git show'
alias gcsS='git show --pretty=short --show-signature' alias gcsS='git show --pretty=short --show-signature'
alias gcl='git-commit-lost' alias gcl='git-commit-lost'
alias gcy='git cherry -v --abbrev' alias gcy='git cherry --verbose --abbrev'
alias gcY='git cherry -v' alias gcY='git cherry --verbose'
# Conflict (C) # Conflict (C)
alias gCl='git --no-pager diff --name-only --diff-filter=U' alias gCl='git --no-pager diff --name-only --diff-filter=U'
@ -183,15 +182,15 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then
alias gir='git reset' alias gir='git reset'
alias giR='git reset --patch' alias giR='git reset --patch'
alias gix='git rm -r --cached' alias gix='git rm -r --cached'
alias giX='git rm -rf --cached' alias giX='git rm -r --force --cached'
# Log (l) # Log (l)
alias gl='git log --topo-order --pretty=format:"${_git_log_medium_format}"' alias gl='git log --topo-order --pretty=format:"$_git_log_medium_format"'
alias gls='git log --topo-order --stat --pretty=format:"${_git_log_medium_format}"' alias gls='git log --topo-order --stat --pretty=format:"$_git_log_medium_format"'
alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${_git_log_medium_format}"' alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"$_git_log_medium_format"'
alias glo='git log --topo-order --pretty=format:"${_git_log_oneline_format}"' alias glo='git log --topo-order --pretty=format:"$_git_log_oneline_format"'
alias glg='git log --topo-order --graph --pretty=format:"${_git_log_oneline_format}"' alias glg='git log --topo-order --graph --pretty=format:"$_git_log_oneline_format"'
alias glb='git log --topo-order --pretty=format:"${_git_log_brief_format}"' alias glb='git log --topo-order --pretty=format:"$_git_log_brief_format"'
alias glc='git shortlog --summary --numbered' alias glc='git shortlog --summary --numbered'
alias glS='git log --show-signature' alias glS='git log --show-signature'
@ -258,19 +257,19 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then
# Tag (t) # Tag (t)
alias gt='git tag' alias gt='git tag'
alias gtl='git tag -l' alias gtl='git tag --list'
alias gts='git tag -s' alias gts='git tag --sign'
alias gtv='git verify-tag' alias gtv='git verify-tag'
# Working Copy (w) # Working Copy (w)
alias gws='git status --ignore-submodules=${_git_status_ignore_submodules} --short' alias gws='git status --ignore-submodules=$_git_status_ignore_submodules --short'
alias gwS='git status --ignore-submodules=${_git_status_ignore_submodules}' alias gwS='git status --ignore-submodules=$_git_status_ignore_submodules'
alias gwd='git diff --no-ext-diff' alias gwd='git diff --no-ext-diff'
alias gwD='git diff --no-ext-diff --word-diff' alias gwD='git diff --no-ext-diff --word-diff'
alias gwr='git reset --soft' alias gwr='git reset --soft'
alias gwR='git reset --hard' alias gwR='git reset --hard'
alias gwc='git clean -n' alias gwc='git clean --dry-run'
alias gwC='git clean -f' alias gwC='git clean --force'
alias gwx='git rm -r' alias gwx='git rm -r'
alias gwX='git rm -rf' alias gwX='git rm -r --force'
fi fi

View File

@ -22,20 +22,22 @@ function _git-action {
local revert_sequence_formatted local revert_sequence_formatted
for action_dir in \ for action_dir in \
"${git_dir}/rebase-apply" \ "$git_dir/rebase-apply" \
"${git_dir}/rebase" \ "$git_dir/rebase" \
"${git_dir}/../.dotest" "$git_dir/../.dotest"
do do
if [[ -d "$action_dir" ]] ; then if [[ -d "$action_dir" ]] ; then
zstyle -s ':prezto:module:git:info:action:apply' format 'apply_formatted' || apply_formatted='apply' zstyle -s ':prezto:module:git:info:action:apply' format 'apply_formatted' \
zstyle -s ':prezto:module:git:info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase' || apply_formatted='apply'
zstyle -s ':prezto:module:git:info:action:rebase' format 'rebase_formatted' \
|| rebase_formatted='rebase'
if [[ -f "${action_dir}/rebasing" ]] ; then if [[ -f "$action_dir/rebasing" ]] ; then
print "$rebase_formatted" print "$rebase_formatted"
elif [[ -f "${action_dir}/applying" ]] ; then elif [[ -f "$action_dir/applying" ]] ; then
print "$apply_formatted" print "$apply_formatted"
else else
print "${rebase_formatted}/${apply_formatted}" print "$rebase_formatted/$apply_formatted"
fi fi
return 0 return 0
@ -43,59 +45,67 @@ function _git-action {
done done
for action_dir in \ for action_dir in \
"${git_dir}/rebase-merge/interactive" \ "$git_dir/rebase-merge/interactive" \
"${git_dir}/.dotest-merge/interactive" "$git_dir/.dotest-merge/interactive"
do do
if [[ -f "$action_dir" ]]; then if [[ -f "$action_dir" ]]; then
zstyle -s ':prezto:module:git:info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive' zstyle -s ':prezto:module:git:info:action:rebase-interactive' format 'rebase_interactive_formatted' \
|| rebase_interactive_formatted='rebase-interactive'
print "$rebase_interactive_formatted" print "$rebase_interactive_formatted"
return 0 return 0
fi fi
done done
for action_dir in \ for action_dir in \
"${git_dir}/rebase-merge" \ "$git_dir/rebase-merge" \
"${git_dir}/.dotest-merge" "$git_dir/.dotest-merge"
do do
if [[ -d "$action_dir" ]]; then if [[ -d "$action_dir" ]]; then
zstyle -s ':prezto:module:git:info:action:rebase-merge' format 'rebase_merge_formatted' || rebase_merge_formatted='rebase-merge' zstyle -s ':prezto:module:git:info:action:rebase-merge' format 'rebase_merge_formatted' \
|| rebase_merge_formatted='rebase-merge'
print "$rebase_merge_formatted" print "$rebase_merge_formatted"
return 0 return 0
fi fi
done done
if [[ -f "${git_dir}/MERGE_HEAD" ]]; then if [[ -f "$git_dir/MERGE_HEAD" ]]; then
zstyle -s ':prezto:module:git:info:action:merge' format 'merge_formatted' || merge_formatted='merge' zstyle -s ':prezto:module:git:info:action:merge' format 'merge_formatted' \
|| merge_formatted='merge'
print "$merge_formatted" print "$merge_formatted"
return 0 return 0
fi fi
if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then if [[ -f "$git_dir/CHERRY_PICK_HEAD" ]]; then
if [[ -d "${git_dir}/sequencer" ]] ; then if [[ -d "$git_dir/sequencer" ]] ; then
zstyle -s ':prezto:module:git:info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence' zstyle -s ':prezto:module:git:info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' \
|| cherry_pick_sequence_formatted='cherry-pick-sequence'
print "$cherry_pick_sequence_formatted" print "$cherry_pick_sequence_formatted"
else else
zstyle -s ':prezto:module:git:info:action:cherry-pick' format 'cherry_pick_formatted' || cherry_pick_formatted='cherry-pick' zstyle -s ':prezto:module:git:info:action:cherry-pick' format 'cherry_pick_formatted' \
|| cherry_pick_formatted='cherry-pick'
print "$cherry_pick_formatted" print "$cherry_pick_formatted"
fi fi
return 0 return 0
fi fi
if [[ -f "${git_dir}/REVERT_HEAD" ]]; then if [[ -f "$git_dir/REVERT_HEAD" ]]; then
if [[ -d "${git_dir}/sequencer" ]] ; then if [[ -d "$git_dir/sequencer" ]] ; then
zstyle -s ':prezto:module:git:info:action:revert-sequence' format 'revert_sequence_formatted' || revert_sequence_formatted='revert-sequence' zstyle -s ':prezto:module:git:info:action:revert-sequence' format 'revert_sequence_formatted' \
|| revert_sequence_formatted='revert-sequence'
print "$revert_sequence_formatted" print "$revert_sequence_formatted"
else else
zstyle -s ':prezto:module:git:info:action:revert' format 'revert_formatted' || revert_formatted='revert' zstyle -s ':prezto:module:git:info:action:revert' format 'revert_formatted' \
|| revert_formatted='revert'
print "$revert_formatted" print "$revert_formatted"
fi fi
return 0 return 0
fi fi
if [[ -f "${git_dir}/BISECT_LOG" ]]; then if [[ -f "$git_dir/BISECT_LOG" ]]; then
zstyle -s ':prezto:module:git:info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' zstyle -s ':prezto:module:git:info:action:bisect' format 'bisect_formatted' \
|| bisect_formatted='bisect'
print "$bisect_formatted" print "$bisect_formatted"
return 0 return 0
fi fi

View File

@ -16,7 +16,7 @@ command git fsck --unreachable 2> /dev/null \
| grep 'commit' \ | grep 'commit' \
| awk '{print $3}' \ | awk '{print $3}' \
| command git log \ | command git log \
--pretty=format:${_git_log_oneline_format} \ --pretty=format:$_git_log_oneline_format \
--extended-regexp \ --extended-regexp \
--grep="${1:-(WIP )?[Oo]n [^:]+:}" \ --grep="${1:-(WIP )?[Oo]n [^:]+:}" \
--merges \ --merges \