Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _git-grep: Complete files when outside git repos
- X-seq: zsh-workers 47400
- From: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>
- To: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- Subject: Re: [PATCH] _git-grep: Complete files when outside git repos
- Date: Fri, 25 Sep 2020 07:28:03 +0000
- Archived-at: <https://zsh.org/workers/47400>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-09/810e70b7-18c3-4f75-adfd-4ec7da540849%40www.fastmail.com>
- Authentication-results: zsh.org; iprev=pass (out4-smtp.messagingengine.com) smtp.remote-ip=66.111.4.28; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none
- Cc: "Guido Cella" <guidocella91@xxxxxxxxx>, zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=mime-version:message-id:in-reply-to :references:date:from:to:cc:subject:content-type :content-transfer-encoding; s=fm1; bh=uhTE5/6VN2XKDX4pyjpRWwN3g3 8DSvvuYtUZV44Rz+w=; b=l1t5dlhWTyZE483FwaD1GWrOdyQwjEITtk4GrT0Gxs pfMO0iSxyMQyH3S6cdKO/IzxOdDdlnQG9sLAOlL02UV8Hzgo4Jf34CWr7YV1QmtZ ziUEWgq02dM+6QVfNMvRtqEbBGqKtmD0e2/Exhdv3hsHuWqKKTAWqyyeibaq6W0Z Vr6+pbB42vY1EnBXXdEyWRP/4uOSBDrjqWvGDH0O8+U+jIWVQ3DufEC8D1wtCkwy /lnN7XrYDPmQBa+knmK78UNCTqhrZkh9LhnxbC0aD/riuYx6cRjRdHZlHerofKRA vj4hlKPkdPRhdG1e4wKjQJmk95GkLjaWW52Qd1WJX8/A==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=uhTE5/6VN2XKDX4pyjpRWwN3g38DSvvuYtUZV44Rz +w=; b=ui/xMfdU/SYHESmZ4QDy9LUNz/1lmKA+/yJFaCW6hPKadSQjxrtIAMsu1 hQQMVGbwW8/5FJ6zvP4BBhw1o5J7d1F5ajizRP+t1SkK3bDODshA4JVX2AQJciJm VtVBQskDfk+MBAqm7Dj+qBN8Hl6EsDAPreRQ0s3Z0DdKbyE9ZKW5yiK/bvrmCvRW ch6Kd3eUpydwNETStZA1aDVAYB1vUGLOw9776o2DTcbE/eP7wKOEiNVV/oKLTWgc sYrJbkRTtCuyvHF0L9HWtqzXZkgzAuLrwGKCcYrvCbavfp0ovhpPmOBSm8dVY0Bd rTHs6ciCXLIymsQEn0z9LcCrlqAIg==
- In-reply-to: <CAHYJk3Tg4pNf7H5ZP08cgB1ONH7D5dt3oLw-pWpHZ8sBF3xGHA@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <20200924203441.80963-1-guidocella91@gmail.com> <20200925063411.GD29504@tarpaulin.shahaf.local2> <CAHYJk3Tg4pNf7H5ZP08cgB1ONH7D5dt3oLw-pWpHZ8sBF3xGHA@mail.gmail.com>
- Sender: zsh-workers-request@xxxxxxx
Mikael Magnusson wrote on Fri, 25 Sep 2020 06:49 +00:00:
> On 9/25/20, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> > Guido Cella wrote on Thu, Sep 24, 2020 at 22:34:41 +0200:
> >> ---
> >> Completion/Unix/Command/_git | 6 ++++++
> >> 1 file changed, 6 insertions(+)
> >>
> >> diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
> >> index 05e2a23..67f06c5 100644
> >> --- a/Completion/Unix/Command/_git
> >> +++ b/Completion/Unix/Command/_git
> >> @@ -1037,6 +1037,12 @@ _git-grep () {
> >> # don't complete treeishs.
> >> case $state in
> >> (tree-or-file)
> >> + # Check if we're not in a git repository.
> >> + if ! git rev-parse 2>/dev/null; then
> >> + _files && ret=0
> >> + return ret
> >> + fi
> >
> > Why is this correct? When cwd isn't a repository, «git grep foo ./bar»
> > just errors out:
> > .
> > % ls
> > iota
> > % git grep This iota
> > fatal: not a git repository (or any parent up to mount point /)
> > Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
> > set).
> > zsh: exit 128
> >
> > Does newer git behave differently? If not, shouldn't the behaviour be
> > conditional on --no-index having been passed?
>
> grep.fallbackToNoIndex
> If set to true, fall back to git grep --no-index if git grep is executed
> outside of a git repository. Defaults to false.
>
> [...] it seems easier to just complete files in this
> context since git can be configured to accept them here.
Fair enough. In this case, the patch should be revised to use
_call_program (and possibly discard stdout?).
> I guess if we want to be fancy we can check for this option / command
> line switch, [...]
If we wanted to be fancy, we'd parse the output of `git config --null`
into an associative array at the top of _git, so all _git-foo()
functions would be able to check such things cheaply. (May want to make
this conditional on some opt-in style for performance reasons?)
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author