Skip to content

Commit 3bcb41f

Browse files
szedergitster
authored andcommitted
completion: fix most spots not respecting 'git --git-dir=<path>'
The completion script already respects the path to the repository specified on the command line most of the time, here we add the necessary '--git-dir=$(__gitdir)' options to most of the places where git was executed without it. The exceptions where said option is not added are the git invocations: - in __git_refs() which are non-trivial and will be the subject of the following patch, - getting the list of git commands, merge strategies and archive formats, because these are independent from the repository and thus don't need it, and - the 'git rev-parse --git-dir' in __gitdir() itself. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2f03b0 commit 3bcb41f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,13 @@ __gitcomp_file ()
283283
# argument, and using the options specified in the second argument.
284284
__git_ls_files_helper ()
285285
{
286+
local dir="$(__gitdir)"
287+
286288
if [ "$2" == "--committable" ]; then
287-
git -C "$1" diff-index --name-only --relative HEAD
289+
git --git-dir="$dir" -C "$1" diff-index --name-only --relative HEAD
288290
else
289291
# NOTE: $2 is not quoted in order to support multiple options
290-
git -C "$1" ls-files --exclude-standard $2
292+
git --git-dir="$dir" -C "$1" ls-files --exclude-standard $2
291293
fi 2>/dev/null
292294
}
293295

@@ -408,7 +410,7 @@ __git_refs2 ()
408410
__git_refs_remotes ()
409411
{
410412
local i hash
411-
git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
413+
git --git-dir="$(__gitdir)" ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
412414
while read -r hash i; do
413415
echo "$i:refs/remotes/$1/${i#refs/heads/}"
414416
done
@@ -1186,7 +1188,7 @@ _git_commit ()
11861188
return
11871189
esac
11881190

1189-
if git rev-parse --verify --quiet HEAD >/dev/null; then
1191+
if git --git-dir="$(__gitdir)" rev-parse --verify --quiet HEAD >/dev/null; then
11901192
__git_complete_index_file "--committable"
11911193
else
11921194
# This is the first commit
@@ -1486,7 +1488,7 @@ _git_log ()
14861488
{
14871489
__git_has_doubledash && return
14881490

1489-
local g="$(git rev-parse --git-dir 2>/dev/null)"
1491+
local g="$(__gitdir)"
14901492
local merge=""
14911493
if [ -f "$g/MERGE_HEAD" ]; then
14921494
merge="--merge"

0 commit comments

Comments
 (0)