fi
}
+# Runs git with all the options given as argument, respecting any
+# '--git-dir=<path>' and '-C <path>' options present on the command line
+__git ()
+{
+ git ${__git_C_args:+"${__git_C_args[@]}"} \
+ ${__git_dir:+--git-dir="$__git_dir"} "$@"
+}
+
# The following function is based on code from:
#
# bash_completion - programmable completion functions for bash 3.2+
# argument, and using the options specified in the second argument.
__git_ls_files_helper ()
{
- local dir="$(__gitdir)"
-
if [ "$2" == "--committable" ]; then
- git ${__git_C_args:+"${__git_C_args[@]}"} --git-dir="$dir" -C "$1" diff-index --name-only --relative HEAD
+ __git -C "$1" diff-index --name-only --relative HEAD
else
# NOTE: $2 is not quoted in order to support multiple options
- git ${__git_C_args:+"${__git_C_args[@]}"} --git-dir="$dir" -C "$1" ls-files --exclude-standard $2
+ __git -C "$1" ls-files --exclude-standard $2
fi 2>/dev/null
}
{
local dir="$(__gitdir)"
if [ -d "$dir" ]; then
- git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
- refs/heads
+ __git for-each-ref --format='%(refname:short)' refs/heads
return
fi
}
{
local dir="$(__gitdir)"
if [ -d "$dir" ]; then
- git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
- refs/tags
+ __git for-each-ref --format='%(refname:short)' refs/tags
return
fi
}
refs="refs/tags refs/heads refs/remotes"
;;
esac
- git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
+ __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \
$refs
if [ -n "$track" ]; then
# employ the heuristic used by git checkout
# Try to find a remote branch that matches the completion word
# but only output if the branch name is unique
local ref entry
- git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
+ __git for-each-ref --shell --format="ref=%(refname:short)" \
"refs/remotes/" | \
while read -r entry; do
eval "$entry"
fi
case "$cur" in
refs|refs/*)
- git --git-dir="$dir" ls-remote "$remote" "$cur*" 2>/dev/null | \
+ __git ls-remote "$remote" "$cur*" 2>/dev/null | \
while read -r hash i; do
case "$i" in
*^{}) ;;
*)
if [ "$list_refs_from" = remote ]; then
echo "HEAD"
- git --git-dir="$dir" for-each-ref --format="%(refname:short)" \
+ __git for-each-ref --format="%(refname:short)" \
"refs/remotes/$remote/" 2>/dev/null | sed -e "s#^$remote/##"
else
- git --git-dir="$dir" ls-remote "$remote" HEAD \
+ __git ls-remote "$remote" HEAD \
"refs/tags/*" "refs/heads/*" "refs/remotes/*" 2>/dev/null |
while read -r hash i; do
case "$i" in
__git_refs_remotes ()
{
local i hash
- git --git-dir="$(__gitdir)" ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
+ __git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
while read -r hash i; do
echo "$i:refs/remotes/$1/${i#refs/heads/}"
done
{
local d="$(__gitdir)"
test -d "$d/remotes" && ls -1 "$d/remotes"
- git --git-dir="$d" remote
+ __git remote
}
# Returns true if $1 matches the name of a configured remote, false otherwise.
*) pfx="$ref:$pfx" ;;
esac
- __gitcomp_nl "$(git ${__git_C_args:+"${__git_C_args[@]}"} --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
+ __gitcomp_nl "$(__git ls-tree "$ls" 2>/dev/null \
| sed '/^100... blob /{
s,^.* ,,
s,$, ,
__git_get_config_variables ()
{
local section="$1" i IFS=$'\n'
- for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
+ for i in $(__git config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
echo "${i#$section.}"
done
}
# __git_aliased_command requires 1 argument
__git_aliased_command ()
{
- local word cmdline=$(git --git-dir="$(__gitdir)" \
- config --get "alias.$1" 2>/dev/null)
+ local word cmdline=$(__git config --get "alias.$1" 2>/dev/null)
for word in $cmdline; do
case "$word" in
\!gitk|gitk)
done
if [ -n "$config_key" ] && [ -z "$result" ]; then
- result="$(git --git-dir="$(__gitdir)" config "$config_key")"
+ result="$(__git config "$config_key")"
fi
echo "$result"
return
esac
- if git --git-dir="$(__gitdir)" rev-parse --verify --quiet HEAD >/dev/null; then
+ if __git rev-parse --verify --quiet HEAD >/dev/null; then
__git_complete_index_file "--committable"
else
# This is the first commit
case "$prev" in
--to|--cc|--bcc|--from)
__gitcomp "
- $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
+ $(__git send-email --dump-aliases 2>/dev/null)
"
return
;;
;;
--to=*|--cc=*|--bcc=*|--from=*)
__gitcomp "
- $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
+ $(__git send-email --dump-aliases 2>/dev/null)
" "" "${cur#--*=}"
return
;;
c=$((--c))
done
- git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
+ __git config $config_file --name-only --list 2>/dev/null
}
_git_config ()
remote.*.push)
local remote="${prev#remote.}"
remote="${remote%.push}"
- __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
- for-each-ref --format='%(refname):%(refname)' \
- refs/heads)"
+ __gitcomp_nl "$(__git for-each-ref
+ --format='%(refname):%(refname)' refs/heads)"
return
;;
pull.twohead|pull.octopus)
if [ $cword -eq 3 ]; then
__gitcomp_nl "$(__git_refs)";
else
- __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
+ __gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')"
fi
;;
show,*|apply,*|drop,*|pop,*)
- __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
+ __gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')"
;;
*)