completion: discover repo path in `__git_pseudoref_exists ()`

The helper function `__git_pseudoref_exists ()` expects that the repo path has already been discovered by its callers, which makes for a rather fragile calling convention. Refactor the function to discover the repo path itself to make it more self-contained, which also removes the need to discover the path in some of its callers. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 15, 2024 at 11:35 UTC 3bf5ccf429561a1fbd64cc55b771e31aae15065c
1 file changed +2 -3
contrib/completion/git-completion.bash
+2 -3
@@ -138,6 +138,8 @@ __git_pseudoref_exists ()
138 {
139 local ref=$1
140
141 + __git_find_repo_path
142 +
143 # If the reftable is in use, we have to shell out to 'git rev-parse'
144 # to determine whether the ref exists instead of looking directly in
145 # the filesystem to determine whether the ref exists. Otherwise, use
@@ -1656,7 +1658,6 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1658
1659 _git_cherry_pick ()
1660 {
1659 - __git_find_repo_path
1661 if __git_pseudoref_exists CHERRY_PICK_HEAD; then
1662 __gitcomp "$__git_cherry_pick_inprogress_options"
1663 return
@@ -2966,7 +2967,6 @@ _git_reset ()
2967
2968 _git_restore ()
2969 {
2969 - __git_find_repo_path
2970 case "$prev" in
2971 -s)
2972 __git_complete_refs
@@ -2995,7 +2995,6 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2995
2996 _git_revert ()
2997 {
2998 - __git_find_repo_path
2998 if __git_pseudoref_exists REVERT_HEAD; then
2999 __gitcomp "$__git_revert_inprogress_options"
3000 return