1
0
Fork 0
mirror of synced 2024-11-14 20:18:58 -05:00
zimfw/modules/git-info/functions/git-action
Eric Nielsen 539f8ae8df [git] Move git-action to its own autoloadable file
instead of redefining the function constantly inside git-info.
2018-05-09 20:22:32 -05:00

80 lines
2.5 KiB
Bash

# vim:et sts=2 sw=2 ft=zsh
# Gets the Git special action (am, bisect, cherry, merge, rebase).
# Borrowed from vcs_info and edited.
local git_dir=${$(command git rev-parse --git-dir):A}
local action_dir
for action_dir in \
"${git_dir}/rebase-apply" \
"${git_dir}/rebase" \
"${git_dir}/../.dotest"
do
if [[ -d ${action_dir} ]]; then
local apply_formatted rebase_formatted
zstyle -s ':zim:git-info:action:apply' format 'apply_formatted' || apply_formatted='apply'
zstyle -s ':zim:git-info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase'
if [[ -f "${action_dir}/rebasing" ]]; then
print ${rebase_formatted}
elif [[ -f "${action_dir}/applying" ]]; then
print ${apply_formatted}
else
print "${rebase_formatted}/${apply_formatted}"
fi
return 0
fi
done
for action_dir in \
"${git_dir}/rebase-merge/interactive" \
"${git_dir}/.dotest-merge/interactive"
do
if [[ -f ${action_dir} ]]; then
local rebase_interactive_formatted
zstyle -s ':zim:git-info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive'
print ${rebase_interactive_formatted}
return 0
fi
done
for action_dir in \
"${git_dir}/rebase-merge" \
"${git_dir}/.dotest-merge"
do
if [[ -d ${action_dir} ]]; then
local rebase_merge_formatted
zstyle -s ':zim:git-info:action:rebase-merge' format 'rebase_merge_formatted' || rebase_merge_formatted='rebase-merge'
print ${rebase_merge_formatted}
return 0
fi
done
if [[ -f "${git_dir}/MERGE_HEAD" ]]; then
local merge_formatted
zstyle -s ':zim:git-info:action:merge' format 'merge_formatted' || merge_formatted='merge'
print ${merge_formatted}
return 0
fi
if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then
if [[ -d "${git_dir}/sequencer" ]]; then
local cherry_pick_sequence_formatted
zstyle -s ':zim:git-info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence'
print ${cherry_pick_sequence_formatted}
else
local cherry_pick_formatted
zstyle -s ':zim:git-info:action:cherry-pick' format 'cherry_pick_formatted' || cherry_pick_formatted='cherry-pick'
print ${cherry_pick_formatted}
fi
return 0
fi
if [[ -f "${git_dir}/BISECT_LOG" ]]; then
local bisect_formatted
zstyle -s ':zim:git-info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect'
print ${bisect_formatted}
return 0
fi
return 1