Browse Source

Merge branch 'tp/completion'

* tp/completion:
  Fixup: Add bare repository indicator for __git_ps1
  Add bare repository indicator for __git_ps1
  completion: More fixes to prevent unbound variable errors
  completion: Better __git_ps1 support when not in working directory
  completion: Use consistent if [...] convention, not "test"
  completion: For consistency, change "git rev-parse" to __gitdir calls
maint
Junio C Hamano 16 years ago
parent
commit
229e65823a
  1. 80
      contrib/completion/git-completion.bash

80
contrib/completion/git-completion.bash

@ -62,7 +62,7 @@ esac
__gitdir () __gitdir ()
{ {
if [ -z "${1-}" ]; then if [ -z "${1-}" ]; then
if [ -n "$__git_dir" ]; then if [ -n "${__git_dir-}" ]; then
echo "$__git_dir" echo "$__git_dir"
elif [ -d .git ]; then elif [ -d .git ]; then
echo .git echo .git
@ -80,68 +80,72 @@ __gitdir ()
# returns text to add to bash PS1 prompt (includes branch name) # returns text to add to bash PS1 prompt (includes branch name)
__git_ps1 () __git_ps1 ()
{ {
local g="$(git rev-parse --git-dir 2>/dev/null)" local g="$(__gitdir)"
if [ -n "$g" ]; then if [ -n "$g" ]; then
local r local r
local b local b
if [ -d "$g/rebase-apply" ] if [ -d "$g/rebase-apply" ]; then
then if [ -f "$g/rebase-apply/rebasing" ]; then
if test -f "$g/rebase-apply/rebasing"
then
r="|REBASE" r="|REBASE"
elif test -f "$g/rebase-apply/applying" elif [ -f "$g/rebase-apply/applying" ]; then
then
r="|AM" r="|AM"
else else
r="|AM/REBASE" r="|AM/REBASE"
fi fi
b="$(git symbolic-ref HEAD 2>/dev/null)" b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/rebase-merge/interactive" ] elif [ -f "$g/rebase-merge/interactive" ]; then
then
r="|REBASE-i" r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")" b="$(cat "$g/rebase-merge/head-name")"
elif [ -d "$g/rebase-merge" ] elif [ -d "$g/rebase-merge" ]; then
then
r="|REBASE-m" r="|REBASE-m"
b="$(cat "$g/rebase-merge/head-name")" b="$(cat "$g/rebase-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ] elif [ -f "$g/MERGE_HEAD" ]; then
then
r="|MERGING" r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)" b="$(git symbolic-ref HEAD 2>/dev/null)"
else else
if [ -f "$g/BISECT_LOG" ] if [ -f "$g/BISECT_LOG" ]; then
then
r="|BISECTING" r="|BISECTING"
fi fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)" if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
then if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)" if [ -r "$g/HEAD" ]; then
then b="$(cut -c1-7 "$g/HEAD")..."
b="$(cut -c1-7 "$g/HEAD")..." fi
fi fi
fi fi
fi fi


local w local w
local i local i
local c


if test -n "${GIT_PS1_SHOWDIRTYSTATE-}"; then if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
if test "$(git config --bool bash.showDirtyState)" != "false"; then if [ "true" = "$(git config --bool core.bare 2>/dev/null)" ]; then
git diff --no-ext-diff --ignore-submodules \ c="BARE:"
--quiet --exit-code || w="*" else
if git rev-parse --quiet --verify HEAD >/dev/null; then b="GIT_DIR!"
git diff-index --cached --quiet \ fi
--ignore-submodules HEAD -- || i="+" elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
else if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
i="#" if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
git diff --no-ext-diff --ignore-submodules \
--quiet --exit-code || w="*"
if git rev-parse --quiet --verify HEAD >/dev/null; then
git diff-index --cached --quiet \
--ignore-submodules HEAD -- || i="+"
else
i="#"
fi
fi fi
fi fi
fi fi


if [ -n "${1-}" ]; then if [ -n "$b" ]; then
printf "$1" "${b##refs/heads/}$w$i$r" if [ -n "${1-}" ]; then
else printf "$1" "$c${b##refs/heads/}$w$i$r"
printf " (%s)" "${b##refs/heads/}$w$i$r" else
printf " (%s)" "$c${b##refs/heads/}$w$i$r"
fi
fi fi
fi fi
} }
@ -299,7 +303,7 @@ __git_remotes ()


__git_merge_strategies () __git_merge_strategies ()
{ {
if [ -n "$__git_merge_strategylist" ]; then if [ -n "${__git_merge_strategylist-}" ]; then
echo "$__git_merge_strategylist" echo "$__git_merge_strategylist"
return return
fi fi
@ -385,7 +389,7 @@ __git_complete_revlist ()


__git_all_commands () __git_all_commands ()
{ {
if [ -n "$__git_all_commandlist" ]; then if [ -n "${__git_all_commandlist-}" ]; then
echo "$__git_all_commandlist" echo "$__git_all_commandlist"
return return
fi fi
@ -403,7 +407,7 @@ __git_all_commandlist="$(__git_all_commands 2>/dev/null)"


__git_porcelain_commands () __git_porcelain_commands ()
{ {
if [ -n "$__git_porcelain_commandlist" ]; then if [ -n "${__git_porcelain_commandlist-}" ]; then
echo "$__git_porcelain_commandlist" echo "$__git_porcelain_commandlist"
return return
fi fi
@ -1841,7 +1845,7 @@ _gitk ()
__git_has_doubledash && return __git_has_doubledash && return


local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
local g="$(git rev-parse --git-dir 2>/dev/null)" local g="$(__gitdir)"
local merge="" local merge=""
if [ -f $g/MERGE_HEAD ]; then if [ -f $g/MERGE_HEAD ]; then
merge="--merge" merge="--merge"

Loading…
Cancel
Save