diff mbox series

[v4,1/3] completion: add sparse-checkout tests

Message ID 5bb598a055dd8121ad5c7228b11618b037029478.1643318514.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series completion: sparse-checkout updates | expand

Commit Message

Lessley Dennington Jan. 27, 2022, 9:21 p.m. UTC
From: Lessley Dennington <lessleydennington@gmail.com>

Add tests for missing/incorrect components of custom tab completion for
the sparse-checkout command. These tests specifically highlight the
following:

1. git sparse-checkout <TAB> results in an incomplete list of subcommands
(it is missing reapply and add).
2. git sparse-checkout set <TAB> and git sparse-checkout add <TAB> show
both file names and directory names. While this is the correct behavior
for non-cone mode, cone mode sparse checkouts should complete only
directory names.

Although the first two of these tests currently fail, they will succeed
with the sparse-checkout modifications in git-completion.bash in the next
commit in this series.

Signed-off-by: Lessley Dennington <lessleydennington@gmail.com>
---
 t/t9902-completion.sh | 75 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

Comments

Elijah Newren Jan. 28, 2022, 12:08 a.m. UTC | #1
On Thu, Jan 27, 2022 at 1:21 PM Lessley Dennington via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Lessley Dennington <lessleydennington@gmail.com>
>
> Add tests for missing/incorrect components of custom tab completion for
> the sparse-checkout command. These tests specifically highlight the
> following:
>
> 1. git sparse-checkout <TAB> results in an incomplete list of subcommands
> (it is missing reapply and add).
> 2. git sparse-checkout set <TAB> and git sparse-checkout add <TAB> show
> both file names and directory names. While this is the correct behavior

s/is/may be/

(Yes, Junio declared it to be the behavior he wanted to see, but
there's a difference between "this is clearly desired behavior" and
"here's the official edict declaring which bad option is the lesser
evil" situation.  As Junio pointed out, completing on files and
directories avoids one type of surprise for users -- but as I've
pointed out elsewhere, it introduces multiple other types of negative
surprises.)

> for non-cone mode, cone mode sparse checkouts should complete only
> directory names.
>
> Although the first two of these tests currently fail, they will succeed
> with the sparse-checkout modifications in git-completion.bash in the next
> commit in this series.
>
> Signed-off-by: Lessley Dennington <lessleydennington@gmail.com>
> ---
>  t/t9902-completion.sh | 75 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 75 insertions(+)
>
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 518203fbe07..6004d854102 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -1447,6 +1447,81 @@ test_expect_success 'git checkout - with --detach, complete only references' '
>         EOF
>  '
>
> +test_expect_failure 'sparse-checkout completes subcommands' '
> +       test_completion "git sparse-checkout " <<-\EOF
> +       list Z
> +       init Z
> +       set Z
> +       add Z
> +       reapply Z
> +       disable Z
> +       EOF
> +'
> +
> +test_expect_failure 'cone mode sparse-checkout completes directory names' '
> +       # set up sparse-checkout repo
> +       git init sparse-checkout &&
> +       (
> +               cd sparse-checkout &&
> +               mkdir -p folder1/0/1 folder2/0 folder3 &&
> +               touch folder1/0/1/t.txt &&
> +               touch folder2/0/t.txt &&
> +               touch folder3/t.txt &&
> +               git add . &&
> +               git commit -am "Initial commit"
> +       ) &&
> +
> +       # initialize sparse-checkout definitions
> +       git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
> +
> +       # test tab completion
> +       (
> +               cd sparse-checkout &&
> +               test_completion "git sparse-checkout set f" <<-\EOF
> +               folder1
> +               folder2
> +               folder3
> +               EOF
> +       ) &&
> +
> +       (
> +               cd sparse-checkout &&
> +               test_completion "git sparse-checkout set folder1/" <<-\EOF
> +               folder1/0
> +               EOF
> +       ) &&
> +
> +       (
> +               cd sparse-checkout &&
> +               test_completion "git sparse-checkout set folder1/0/" <<-\EOF
> +               folder1/0/1
> +               EOF
> +       ) &&
> +
> +       (
> +               cd sparse-checkout/folder1 &&
> +               test_completion "git sparse-checkout add 0" <<-\EOF
> +               0
> +               EOF
> +       )
> +'
> +
> +test_expect_success 'non-cone mode sparse-checkout uses bash completion' '
> +       # reset sparse-checkout repo to non-cone mode
> +       git -C sparse-checkout sparse-checkout disable &&
> +       git -C sparse-checkout sparse-checkout set &&

Can we add a --no-cone here in preparation for the default to switch?


> +
> +       # test tab completion
> +       (
> +               cd sparse-checkout &&
> +               # expected to be empty since we have not configured
> +               # custom completion for non-cone mode
> +               test_completion "git sparse-checkout set f" <<-\EOF
> +
> +               EOF
> +       )
> +'
> +
>  test_expect_success 'git switch - with -d, complete all references' '
>         test_completion "git switch -d " <<-\EOF
>         HEAD Z
> --
> gitgitgadget
>
Junio C Hamano Jan. 28, 2022, 1:56 a.m. UTC | #2
Elijah Newren <newren@gmail.com> writes:

> On Thu, Jan 27, 2022 at 1:21 PM Lessley Dennington via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
>> From: Lessley Dennington <lessleydennington@gmail.com>
>>
>> Add tests for missing/incorrect components of custom tab completion for
>> the sparse-checkout command. These tests specifically highlight the
>> following:
>>
>> 1. git sparse-checkout <TAB> results in an incomplete list of subcommands
>> (it is missing reapply and add).
>> 2. git sparse-checkout set <TAB> and git sparse-checkout add <TAB> show
>> both file names and directory names. While this is the correct behavior
>
> s/is/may be/

I would stop at "this may be a less surprising behaviour" without
going into "correctness".

>> +test_expect_success 'non-cone mode sparse-checkout uses bash completion' '
>> +       # reset sparse-checkout repo to non-cone mode
>> +       git -C sparse-checkout sparse-checkout disable &&
>> +       git -C sparse-checkout sparse-checkout set &&
>
> Can we add a --no-cone here in preparation for the default to switch?

It would be good to do so, if we plan to switch the default.
Elijah Newren Jan. 28, 2022, 2:04 a.m. UTC | #3
On Thu, Jan 27, 2022 at 5:56 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Elijah Newren <newren@gmail.com> writes:
>
> > On Thu, Jan 27, 2022 at 1:21 PM Lessley Dennington via GitGitGadget
> > <gitgitgadget@gmail.com> wrote:
> >>
> >> From: Lessley Dennington <lessleydennington@gmail.com>
> >>
> >> Add tests for missing/incorrect components of custom tab completion for
> >> the sparse-checkout command. These tests specifically highlight the
> >> following:
> >>
> >> 1. git sparse-checkout <TAB> results in an incomplete list of subcommands
> >> (it is missing reapply and add).
> >> 2. git sparse-checkout set <TAB> and git sparse-checkout add <TAB> show
> >> both file names and directory names. While this is the correct behavior
> >
> > s/is/may be/
>
> I would stop at "this may be a less surprising behaviour" without
> going into "correctness".

Ooh, I like that wording even better.

> >> +test_expect_success 'non-cone mode sparse-checkout uses bash completion' '
> >> +       # reset sparse-checkout repo to non-cone mode
> >> +       git -C sparse-checkout sparse-checkout disable &&
> >> +       git -C sparse-checkout sparse-checkout set &&
> >
> > Can we add a --no-cone here in preparation for the default to switch?
>
> It would be good to do so, if we plan to switch the default.

We've talked about it for a few cycles, so I created a patch series to
do so.  But it depends on two or three in-flight series (from
Victoria, myself, and now Stolee) to avoid textual conflicts, so I've
been waiting for those to settle.
diff mbox series

Patch

diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 518203fbe07..6004d854102 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1447,6 +1447,81 @@  test_expect_success 'git checkout - with --detach, complete only references' '
 	EOF
 '
 
+test_expect_failure 'sparse-checkout completes subcommands' '
+	test_completion "git sparse-checkout " <<-\EOF
+	list Z
+	init Z
+	set Z
+	add Z
+	reapply Z
+	disable Z
+	EOF
+'
+
+test_expect_failure 'cone mode sparse-checkout completes directory names' '
+	# set up sparse-checkout repo
+	git init sparse-checkout &&
+	(
+		cd sparse-checkout &&
+		mkdir -p folder1/0/1 folder2/0 folder3 &&
+		touch folder1/0/1/t.txt &&
+		touch folder2/0/t.txt &&
+		touch folder3/t.txt &&
+		git add . &&
+		git commit -am "Initial commit"
+	) &&
+
+	# initialize sparse-checkout definitions
+	git -C sparse-checkout sparse-checkout set --cone folder1/0 folder3 &&
+
+	# test tab completion
+	(
+		cd sparse-checkout &&
+		test_completion "git sparse-checkout set f" <<-\EOF
+		folder1
+		folder2
+		folder3
+		EOF
+	) &&
+
+	(
+		cd sparse-checkout &&
+		test_completion "git sparse-checkout set folder1/" <<-\EOF
+		folder1/0
+		EOF
+	) &&
+
+	(
+		cd sparse-checkout &&
+		test_completion "git sparse-checkout set folder1/0/" <<-\EOF
+		folder1/0/1
+		EOF
+	) &&
+
+	(
+		cd sparse-checkout/folder1 &&
+		test_completion "git sparse-checkout add 0" <<-\EOF
+		0
+		EOF
+	)
+'
+
+test_expect_success 'non-cone mode sparse-checkout uses bash completion' '
+	# reset sparse-checkout repo to non-cone mode
+	git -C sparse-checkout sparse-checkout disable &&
+	git -C sparse-checkout sparse-checkout set &&
+
+	# test tab completion
+	(
+		cd sparse-checkout &&
+		# expected to be empty since we have not configured
+		# custom completion for non-cone mode
+		test_completion "git sparse-checkout set f" <<-\EOF
+
+		EOF
+	)
+'
+
 test_expect_success 'git switch - with -d, complete all references' '
 	test_completion "git switch -d " <<-\EOF
 	HEAD Z