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 <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Feb 3, 2017 at 03:48 UTC
3bcb41f976e767376d496cf210d82cf39dad0e62
1 file changed
+7
-5
contrib/completion/git-completion.bash
+7
-5
@@ -283,11 +283,13 @@ __gitcomp_file ()
283
# argument, and using the options specified in the second argument.
284
__git_ls_files_helper ()
285
{
286
+ local dir="$(__gitdir)"
287
+
288
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
290
else
291
# 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
293
fi 2>/dev/null
294
}
295
@@ -408,7 +410,7 @@ __git_refs2 ()
410
__git_refs_remotes ()
411
{
412
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 | \
414
while read -r hash i; do
415
echo "$i:refs/remotes/$1/${i#refs/heads/}"
416
done
@@ -1186,7 +1188,7 @@ _git_commit ()
1188
return
1189
esac
1190
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
1192
__git_complete_index_file "--committable"
1193
else
1194
# This is the first commit
@@ -1486,7 +1488,7 @@ _git_log ()
1488
{
1489
__git_has_doubledash && return
1490
1489
- local g="$(git rev-parse --git-dir 2>/dev/null)"
1491
+ local g="$(__gitdir)"
1492
local merge=""
1493
if [ -f "$g/MERGE_HEAD" ]; then
1494
merge="--merge"