git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 4/4] completion: avoid user confusion in non-cone mode
Date: Fri, 24 Nov 2023 10:19:10 +0900	[thread overview]
Message-ID: <xmqqo7fk9cdt.fsf@gitster.g> (raw)
In-Reply-To: <fe8669a3f4f05c186e497f870c7e7ba9a94ac63f.1700761448.git.gitgitgadget@gmail.com> (Elijah Newren via GitGitGadget's message of "Thu, 23 Nov 2023 17:44:08 +0000")

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  		if [[ "$using_cone" == "true" ]]; then
>  			__gitcomp_directories

Hmph, doesn't "Providing the files and directories currently present
is thus always wrong." apply equally to cone mode?

> +		else
> +			# NEEDSWORK: It might be useful to provide a
> +			# completion function which:
> +			#
> +			#     1. Provides completions based on
> +			#        files/directories that exist in HEAD, not
> +			#        just those currently present in the working
> +			#        tree.

This makes a lot of sense.  May make even more sense with
s/HEAD/index/, though.

> +			#     4. Provides no completions when run from a
> +			#        subdirectory of the repository root.  (If we
> +			#        did provide file/directory completions, the
> +			#        user would just get a "please run from the
> +			#        toplevel directory" error message when they
> +			#        ran it.  *Further*, if the user did rerun
> +			#        the command from the toplevel, the
> +			#        completions we previously provided would
> +			#        likely be wrong as they'd be relative to the
> +			#        subdirectory rather than the repository
> +			#        root.  That could lead to users getting a
> +			#        nasty surprise based on trying to use a
> +			#        command we helped them create.)

Hmph, would an obvious alternative to (1) check against the HEAD (or
the index) to see if the prefix string matches an entity at the
current directory level, and then (2) to prefix the result of the
previous step with "/$(git rev-parse --show-prefix)" work?  That is
something like this:

    $ cd t
    $ git sparse-checkout add help<TAB>
    ->
    $ git sparse-checkout add /t/helper/

and when the user gave the full path from the root level, do the
obvious:

    $ cd t
    $ git sparse-checkout add /t/help<TAB>
    ->
    $ git sparse-checkout add /t/helper/

Another more fundamental approach to avoid "confusion" this bullet
item tries to side step might be to *fix* the command that gets
completed.  As "git sparse-checkout --help" is marked as
EXPERIMENTAL in capital letters, we should be able to say "what was
traditionally known as 'add' is from now on called 'add-pattern' and
command line completion would not get in the way; the 'add'
subcommand now takes only literal paths, not patterns, that are
relative to the current directory" if we wanted to.

> +			#     5. Provides escaped completions for any paths
> +			#        containing a '*', '?', '\', '[', ']', or
> +			#        leading '#' or '!'.  (These characters might
> +			#        already be escaped to protect from the
> +			#        shell, but they need an *extra* layer of
> +			#        escaping to prevent the pattern parsing in
> +			#        Git from seeing them as special characters.)
> +			#
> +			# Of course, this would be a lot of work, so for now,
> +			# just avoid the many forms of user confusion that
> +			# could be caused by providing bad completions by
> +			# providing a fake completion to avoid falling back to
> +			# bash's normal file and directory completion.

> +			COMPREPLY=( "" )
>  		fi
>  	esac
>  }

  reply	other threads:[~2023-11-24  1:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 17:44 [PATCH 0/4] Sparse checkout completion fixes Elijah Newren via GitGitGadget
2023-11-23 17:44 ` [PATCH 1/4] completion: squelch stray errors in sparse-checkout completion Elijah Newren via GitGitGadget
2023-11-24 18:39   ` SZEDER Gábor
2023-11-24 20:05     ` Elijah Newren
2023-11-23 17:44 ` [PATCH 2/4] completion: fix logic for determining whether cone mode is active Elijah Newren via GitGitGadget
2023-11-23 17:44 ` [PATCH 3/4] completion: avoid misleading completions in cone mode Elijah Newren via GitGitGadget
2023-11-23 17:44 ` [PATCH 4/4] completion: avoid user confusion in non-cone mode Elijah Newren via GitGitGadget
2023-11-24  1:19   ` Junio C Hamano [this message]
2023-11-24 15:28     ` Elijah Newren
2023-11-27  1:39       ` Junio C Hamano
2023-12-03  5:57         ` Elijah Newren
2023-11-26  7:51 ` [PATCH v2 0/4] Sparse checkout completion fixes Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 1/4] completion: squelch stray errors in sparse-checkout completion Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 2/4] completion: fix logic for determining whether cone mode is active Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 3/4] completion: avoid misleading completions in cone mode Elijah Newren via GitGitGadget
2023-11-26  7:51   ` [PATCH v2 4/4] completion: avoid user confusion in non-cone mode Elijah Newren via GitGitGadget
2023-12-03  5:57   ` [PATCH v3 0/4] Sparse checkout completion fixes Elijah Newren via GitGitGadget
2023-12-03  5:57     ` [PATCH v3 1/4] completion: squelch stray errors in sparse-checkout completion Elijah Newren via GitGitGadget
2023-12-03  5:57     ` [PATCH v3 2/4] completion: fix logic for determining whether cone mode is active Elijah Newren via GitGitGadget
2023-12-03  5:57     ` [PATCH v3 3/4] completion: avoid misleading completions in cone mode Elijah Newren via GitGitGadget
2023-12-03  5:57     ` [PATCH v3 4/4] completion: avoid user confusion in non-cone mode Elijah Newren via GitGitGadget
2023-12-03 13:15       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqo7fk9cdt.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).