posh-git
posh-git copied to clipboard
git checkout should also autocomplete filepaths without the need for a double dash "--"
The git manual page also states the "--" are optional for git checkout:
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <pathspec>…
https://git-scm.com/docs/git-checkout
The path expansion for git reset does also work with and without "--".
Finally revisiting this - absurdly belated thanks for the issue and PR! Pulling over https://github.com/dahlbyk/posh-git/pull/815#issuecomment-770280114 from @rkeithhill:
My one concern here is that folks used to doing
git checkout <tab>
via posh-git might be a bit surprised to see modified files showing up in the completion list. But if your intent is to switch branches you could usegit switch
AND it is less likely you'd switch branches when you have modified files.
I tend to agree that existing posh-git users might be surprised if paths started showing up where they're used to only seeing branches. Personally, my muscle memory is to explicitly add --
when I want to complete a path. That said, you're right that it's perfectly legal to omit --
unless it's ambiguous.
Tentative suggestions:
- Ensure
git checkout
andgit reset
consistently completely only paths after--
. Currentlygit reset -- <tab>
completes branches/tags, which is incorrect. - While we're at it, path completion for
git reset
probably shouldn't be limited toHEAD
. https://github.com/dahlbyk/posh-git/blob/dc2b6367324a9db79db55186375462a454f29c2e/src/GitTabExpansion.ps1#L404 - Add
$GitTabSettings.DoubleDashOptional
or equivalent (name suggestions?) to allow opting in to including paths fromstatus
without--
. It seems reasonable to me that we would give refs priority over paths, i.e. the path-without---
cases would be added after the ref cases in theswitch -regex
.
Since I proposed and added this PR I didn't use it a single time in my local version. Feel free to choose one of the suggestions or even close this issue (maybe until someone else needs the feature). Sorry for wasting your time and the late response.
I leave the issue open, so you can decide what you want to do with it.