{"thread":{"id":"61357","subject":"Zsh completion: cached __git_repo_path affects shell session, breaks completion","startedAt":"2024-04-24T13:46:50Z","lastAt":"2024-04-24T13:46:50Z","messageCount":1,"participants":["D. Ben Knoble"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"493400","messageId":"CALnO6CBv3+e2WL6n6Mh7ZZHCX2Ni8GpvM4a-bQYxNqjmgZdwdg@mail.gmail.com","threadId":"61357","inReplyTo":null,"subject":"Zsh completion: cached __git_repo_path affects shell session, breaks completion","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2024-04-24T13:46:37Z","receivedAt":"2024-04-24T13:46:50Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"I can only reproduce this in Zsh, not with Bash (using equivalent\ncommands), though the caching behavior comes from Bash (fad9484f0a\n(completion: cache the path to the repository, 2017-02-03)).\n\nFor example (with Zsh):\n\nmkdir a b b/c\nfor d (a b); git -C $d init && git -C $d commit --allow-empty -m init\ncd a\ngit branch foo\npushd ../b/c\ngit branch bar\ngit rebase <TAB>… # completion for bar available; C-c to abort\ndeclare -p __git_repo_path # outputs /path/to/b/.git\npopd\ngit branch # outputs foo, main\ngit rebase <TAB>… # completion candidates are bar, main!\n\nI've only been able to observe this with rebase so far (e.g., using\nswitch instead doesn't seem to trigger the problem).\n\nI wonder if all callers of __git_find_repo_path should declare `local\n__git_repo_path`? That might defeat some caching, but I don't think\n__git_repo_path should be set globally in a shell session, and the\nscript is explicitly intended to be sourced… again, though, I think\nBash does the correct thing and somehow Zsh is capturing this variable\nthat it shouldn't be.\n\n-- \nD. Ben Knoble\n"}]}