Skip to content

Commit a42577d

Browse files
tpavlicgitster
authored andcommitted
bash-completion: Add comments to remind about required arguments
Add a few simple comments above commands that take arguments. These comments are meant to remind developers of potential problems that can occur when the script is sourced on systems with "set -u." Any function which requires arguments really ought to be called with explicit arguments given. Also adds a #!bash to the top of bash completions so that editing software can always identify that the file is of sh type. Signed-off-by: Ted Pavlic <[email protected]> Acked-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50e126e commit a42577d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!bash
12
#
23
# bash completion support for core Git.
34
#
@@ -50,6 +51,8 @@ case "$COMP_WORDBREAKS" in
5051
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
5152
esac
5253

54+
# __gitdir accepts 0 or 1 arguments (i.e., location)
55+
# returns location of .git repo
5356
__gitdir ()
5457
{
5558
if [ -z "${1-}" ]; then
@@ -67,6 +70,8 @@ __gitdir ()
6770
fi
6871
}
6972

73+
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
74+
# returns text to add to bash PS1 prompt (includes branch name)
7075
__git_ps1 ()
7176
{
7277
local g="$(git rev-parse --git-dir 2>/dev/null)"
@@ -119,6 +124,7 @@ __git_ps1 ()
119124
fi
120125
}
121126

127+
# __gitcomp_1 requires 2 arguments
122128
__gitcomp_1 ()
123129
{
124130
local c IFS=' '$'\t'$'\n'
@@ -131,6 +137,8 @@ __gitcomp_1 ()
131137
done
132138
}
133139

140+
# __gitcomp accepts 1, 2, 3, or 4 arguments
141+
# generates completion reply with compgen
134142
__gitcomp ()
135143
{
136144
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -150,6 +158,7 @@ __gitcomp ()
150158
esac
151159
}
152160

161+
# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
153162
__git_heads ()
154163
{
155164
local cmd i is_hash=y dir="$(__gitdir "${1-}")"
@@ -168,6 +177,7 @@ __git_heads ()
168177
done
169178
}
170179

180+
# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
171181
__git_tags ()
172182
{
173183
local cmd i is_hash=y dir="$(__gitdir "${1-}")"
@@ -186,6 +196,7 @@ __git_tags ()
186196
done
187197
}
188198

199+
# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
189200
__git_refs ()
190201
{
191202
local i is_hash=y dir="$(__gitdir "${1-}")"
@@ -218,6 +229,7 @@ __git_refs ()
218229
done
219230
}
220231

232+
# __git_refs2 requires 1 argument (to pass to __git_refs)
221233
__git_refs2 ()
222234
{
223235
local i
@@ -226,6 +238,7 @@ __git_refs2 ()
226238
done
227239
}
228240

241+
# __git_refs_remotes requires 1 argument (to pass to ls-remote)
229242
__git_refs_remotes ()
230243
{
231244
local cmd i is_hash=y
@@ -470,6 +483,7 @@ __git_aliases ()
470483
done
471484
}
472485

486+
# __git_aliased_command requires 1 argument
473487
__git_aliased_command ()
474488
{
475489
local word cmdline=$(git --git-dir="$(__gitdir)" \
@@ -482,6 +496,7 @@ __git_aliased_command ()
482496
done
483497
}
484498

499+
# __git_find_subcommand requires 1 argument
485500
__git_find_subcommand ()
486501
{
487502
local word subcommand c=1

0 commit comments

Comments
 (0)