All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "David Cantrell via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, David Cantrell <david@cantrell.org.uk>
Subject: Re: [PATCH v3] tab completion of filenames for 'git restore'
Date: Tue, 15 Mar 2022 17:44:16 -0700	[thread overview]
Message-ID: <xmqqsfribuan.fsf@gitster.g> (raw)
In-Reply-To: <pull.1227.v3.git.git.1647382437475.gitgitgadget@gmail.com> (David Cantrell via GitGitGadget's message of "Tue, 15 Mar 2022 22:13:57 +0000")

"David Cantrell via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: David Cantrell <david@cantrell.org.uk>
> Subject: Re: [PATCH v3] tab completion of filenames for 'git restore'

Perhaps

    Subject: [PATCH v3] completion: complete modified files for 'git restore'

cf. Documentation/SubmittingPatches::[[summary-section]]


> If no --args are present after 'git restore' it assumes that you want
> to tab-complete one of the files with unstaged uncommitted changes.

Since it is our convention that the first paragraph talks about the
current behaviour, i.e. without the proposed changes applied, in the
present tense, I'd assume the above is what the current code does.

What do you mean by "--args" in this sentence?  Dashed-options?
I am getting the same set of files whose name begins with 'a' from
these two:

 $ git restore a<TAB>
 $ git restore --staged a<TAB>

so, with or without --dashed-options, we complete one of the files,
whether they have any modifications.

Perhaps you meant to say more like:

    When completing a non-option argument to 'git restore', the
    command line completion support offers names of the files
    present in the working tree as candidates.

to describe the status quo; to hint what the shortcoming of the
current behaviour is, we may want to add a bit more, perhaps
append the following at the end of that first paragraph:

    But many of these files may not have any changes, and running
    "restore" on them would be a no-op.  Listing only the files, to
    which doing "restore" is not a no-op, would reduce the clutter.
    
Then we'd continue with the solution, while explaining why the exact
choice between modified vs committable was made:

    Offer only the files that are different from the index, to match
    the default behaviour of "git restore" that checks out the
    contents last added to the index to the working tree.  We could
    instead show the files that are different between the index and
    HEAD, and that is more suittable if "git restore --staged" is
    being completed, but this should do for now.

or something.  The last part is written in such a way to explicitly
signal to future developers that we know we did not do a perfect job
and we do not mind if they extend the logic to use something other
than "--modified" when appropriate.  For example, they could build
on this solution to make it inspect the command line for "--staged"
and "--source" and drive "diff-index" differently to grab the paths
that are offered.  We just do not do that at least for now, but we
have no objection if other people do so in the future.

Thanks.  Will queue as-is for now.

> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 49a328aa8a4..ba5c395d2d8 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2890,6 +2890,10 @@ _git_restore ()
>  	--*)
>  		__gitcomp_builtin restore
>  		;;
> +	*)
> +		if __git rev-parse --verify --quiet HEAD >/dev/null; then
> +			__git_complete_index_file "--modified"
> +		fi
>  	esac
>  }
>  
>
> base-commit: 1a4874565fa3b6668042216189551b98b4dc0b1b

  reply	other threads:[~2022-03-16  0:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 21:07 [PATCH] tab completion of filenames for 'git restore' David Cantrell via GitGitGadget
2022-03-13  6:45 ` Junio C Hamano
2022-03-14 23:45   ` David Cantrell
2022-03-15 10:23     ` Junio C Hamano
2022-03-15  0:52 ` [PATCH v2 0/2] Improved bash tab completion for 'git restore' - adds support for auto-completing filenames David Cantrell via GitGitGadget
2022-03-15  0:52   ` [PATCH v2 1/2] tab completion of filenames for 'git restore' David Cantrell via GitGitGadget
2022-03-15  0:52   ` [PATCH v2 2/2] if a file has been staged we don't want to list it David Cantrell via GitGitGadget
2022-03-16 11:45     ` Bagas Sanjaya
2022-03-15 11:23   ` [PATCH v2 0/2] Improved bash tab completion for 'git restore' - adds support for auto-completing filenames Junio C Hamano
2022-03-15 16:27     ` Junio C Hamano
2022-03-15 22:13   ` [PATCH v3] tab completion of filenames for 'git restore' David Cantrell via GitGitGadget
2022-03-16  0:44     ` Junio C Hamano [this message]
2022-03-17 22:16       ` David Cantrell

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=xmqqsfribuan.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=david@cantrell.org.uk \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.