Merge branch 'nd/parseopt-completion' into next
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:34:19 +0000 (14:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:34:19 +0000 (14:34 -0700)
Hotfix for recently graduated topic that give help to completion
scripts from the Git subcommands that are being completed

* nd/parseopt-completion:
completion: clear cached --options when sourcing the completion script

contrib/completion/git-completion.bash
t/t9902-completion.sh
index c7957f0a90b3ccc62f0ded999c34c963f320419b..b09c8a23626b431a0cb97f6f7f930cccce25bf07 100644 (file)
@@ -280,6 +280,10 @@ __gitcomp ()
        esac
 }
 
+# Clear the variables caching builtins' options when (re-)sourcing
+# the completion script.
+unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
+
 # This function is equivalent to
 #
 #    __gitcomp "$(git xxx --git-completion-helper) ..."
index e6485feb0a0599769b8fba1a0ccd1f9fe41ba1fd..4c86adadf29abc77b4675d16f1676065387b4728 100755 (executable)
@@ -1497,4 +1497,35 @@ do
        '
 done
 
+test_expect_success 'sourcing the completion script clears cached commands' '
+       __git_compute_all_commands &&
+       verbose test -n "$__git_all_commands" &&
+       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+       verbose test -z "$__git_all_commands"
+'
+
+test_expect_success 'sourcing the completion script clears cached porcelain commands' '
+       __git_compute_porcelain_commands &&
+       verbose test -n "$__git_porcelain_commands" &&
+       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+       verbose test -z "$__git_porcelain_commands"
+'
+
+test_expect_success 'sourcing the completion script clears cached merge strategies' '
+       __git_compute_merge_strategies &&
+       verbose test -n "$__git_merge_strategies" &&
+       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+       verbose test -z "$__git_merge_strategies"
+'
+
+test_expect_success 'sourcing the completion script clears cached --options' '
+       __gitcomp_builtin checkout &&
+       verbose test -n "$__gitcomp_builtin_checkout" &&
+       __gitcomp_builtin notes_edit &&
+       verbose test -n "$__gitcomp_builtin_notes_edit" &&
+       . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+       verbose test -z "$__gitcomp_builtin_checkout" &&
+       verbose test -z "$__gitcomp_builtin_notes_edit"
+'
+
 test_done