diff options
author | Jacob Keller <jacob.keller@gmail.com> | 2020-05-28 11:10:43 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-05-28 12:53:24 -0700 |
commit | 4e79adf4e57cbb514e026f9fa2b1f4f7f7a0a2ae (patch) | |
tree | 4b0ffaa6861329f5a9698ab405bd0bcb42c1e303 /t | |
parent | completion: perform DWIM logic directly in __git_complete_refs (diff) | |
download | tgif-4e79adf4e57cbb514e026f9fa2b1f4f7f7a0a2ae.tar.xz |
completion: improve handling of DWIM mode for switch/checkout
A new helper, __git_find_last_on_cmdline is introduced, similar to the
already existing __git_find_on_cmdline, but which operates in reverse,
finding the *last* matching word of the provided wordlist.
Use this in a new __git_checkout_default_dwim_mode() function that will
determine when to enable listing of DWIM remote branches.
The __git_find_last_on_cmdline() function is used to determine which
--guess or --no-guess is in effect. If either one is provided, then we
unconditionally enable or disable the DWIM mode based on the last
provided option.
If neither --guess nor --no-guess is provided, then we check for
--no-track, and finally for GIT_COMPLETION_CHECKOUT_NO_GUESS=1.
This function is then used in _git_switch and _git_checkout to improve
the handling for when we enable listing of these DWIM remote branches.
This new logic is more robust, as we will correctly identify superseded
options, and ensure that both _git_switch and _git_checkout enable DWIM
in similar ways.
We can now update a few tests to indicate they pass. A few of the tests
previously added to highlight issues with the old DWIM logic still fail.
This is because of a separate issue related to the default completion
behavior of git switch, which will be addressed in a future change.
Additionally, due to this change, a few tests for the -b/-B handling of
git checkout now fail. This is a minor regression, and will be fixed by
a following change that improves the overall handling of -b/-B. Mark
these tests as known breakages for now.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t9902-completion.sh | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 8375c4df94..2ce2c23cdf 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1277,7 +1277,6 @@ test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, compl EOF ' -#TODO: --guess/--no-guess ordering is not taken into account #TODO: git switch completion includes unexpected references test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' ' GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF @@ -1288,7 +1287,6 @@ test_expect_failure 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_G EOF ' -#TODO: --guess/--no-guess ordering is not taken into account #TODO: git switch completion includes unexpected references test_expect_failure 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' test_completion "git switch --no-guess --guess " <<-\EOF @@ -1299,8 +1297,7 @@ test_expect_failure 'git switch - a later --guess overrides previous --no-guess, EOF ' -#TODO: --guess/--no-guess ordering is not taken into account -test_expect_failure 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' +test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' test_completion "git switch --guess --no-guess " <<-\EOF master Z matching-branch Z @@ -1318,8 +1315,7 @@ test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only complete EOF ' -#TODO: git checkout does not override variable when --guess is provided -test_expect_failure 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' +test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF HEAD Z branch-in-other Z @@ -1343,8 +1339,7 @@ test_expect_success 'git checkout - with --no-guess, only completes refs' ' EOF ' -#TODO: --guess/--no-guess ordering is not taken into account -test_expect_failure 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' +test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' test_completion "git checkout --no-guess --guess " <<-\EOF HEAD Z branch-in-other Z @@ -1544,7 +1539,8 @@ test_expect_failure 'git checkout - with -B, complete all references' ' EOF ' -test_expect_success 'git checkout - with -b and --track, complete all references' ' +#TODO: completing the start point of -b/-B should not include DWIM references +test_expect_failure 'git checkout - with -b and --track, complete all references' ' test_completion "git checkout -b new-branch --track " <<-EOF HEAD Z master Z @@ -1555,7 +1551,8 @@ test_expect_success 'git checkout - with -b and --track, complete all references EOF ' -test_expect_success 'git checkout - with -B and --track, complete all references' ' +#TODO: completing the start point of -b/-B should not include DWIM references +test_expect_failure 'git checkout - with -B and --track, complete all references' ' test_completion "git checkout -B new-branch --track " <<-EOF HEAD Z master Z |