posh-git icon indicating copy to clipboard operation
posh-git copied to clipboard

git checkout should also autocomplete filepaths without the need for a double dash "--"

Open dannoe opened this issue 3 years ago • 2 comments

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 "--".

dannoe avatar Nov 21 '20 13:11 dannoe

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 use git 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:

  1. Ensure git checkout and git reset consistently completely only paths after --. Currently git reset -- <tab> completes branches/tags, which is incorrect.
  2. While we're at it, path completion for git reset probably shouldn't be limited to HEAD. https://github.com/dahlbyk/posh-git/blob/dc2b6367324a9db79db55186375462a454f29c2e/src/GitTabExpansion.ps1#L404
  3. Add $GitTabSettings.DoubleDashOptional or equivalent (name suggestions?) to allow opting in to including paths from status 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 the switch -regex.

dahlbyk avatar Mar 31 '22 05:03 dahlbyk

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.

dannoe avatar Jul 27 '22 07:07 dannoe