git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Zsh completion: cached __git_repo_path affects shell session, breaks completion

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Apr 24, 2024, 13:46 UTC
Message-ID
<CALnO6CBv3+e2WL6n6Mh7ZZHCX2Ni8GpvM4a-bQYxNqjmgZdwdg@mail.gmail.com>

I can only reproduce this in Zsh, not with Bash (using equivalent commands), though the caching behavior comes from Bash (fad9484f0a (completion: cache the path to the repository, 2017-02-03)).

For example (with Zsh):

mkdir a b b/c for d (a b); git -C $d init && git -C $d commit --allow-empty -m init cd a git branch foo pushd ../b/c git branch bar git rebase <TAB>… # completion for bar available; C-c to abort declare -p __git_repo_path # outputs /path/to/b/.git popd git branch # outputs foo, main git rebase <TAB>… # completion candidates are bar, main!

I've only been able to observe this with rebase so far (e.g., using switch instead doesn't seem to trigger the problem).

I wonder if all callers of __git_find_repo_path should declare `local __git_repo_path`? That might defeat some caching, but I don't think __git_repo_path should be set globally in a shell session, and the script is explicitly intended to be sourced… again, though, I think Bash does the correct thing and somehow Zsh is capturing this variable that it shouldn't be.

-- 
D. Ben Knoble
Message 1 of 1 in “Zsh completion: cached __git_repo_path affects shell session, breaks completion”
  1. D. Ben KnobleApr 24, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.