Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in behavior of tab-completion #974

Open
Kralizek opened this issue Sep 12, 2024 · 7 comments
Open

Change in behavior of tab-completion #974

Kralizek opened this issue Sep 12, 2024 · 7 comments

Comments

@Kralizek
Copy link

System Details

  • posh-git version/path: 1.1.0
  • PowerShell version: 7.4.5
  • git version 2.46.0.windows.1
  • OS: Microsoft Windows NT 10.0.22631.0

Issue Description

I am not sure this is a posh-git issue but I could replicate it on both pwsh (with oh-my-posh) and powershell (clean)

The issue is simple: autocompletion used to be smart about files.

e.g.

$ git status
On branch yarp-entrypoint
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   tools/AppHost/AppHost.csproj
        deleted:    tools/AppHost/Extensions/YarpResourceExtensions.cs
        modified:   tools/AppHost/Program.cs

no changes added to commit (use "git add" and/or "git commit -a")

If I start typing git add <tab> I used to be able to cycle through the dirty files and pick which one I wanted to add. Now instead it cycles through all files and directories, even .git/

This behavior has changed recently and I am trying to understand what caused it and how to revert it because it seriously affects my workflow.

@KlemensE
Copy link

I had the same issue while using oh-my-posh. Changing the source property from cli to pwsh for the git segment helped.

@Kralizek
Copy link
Author

Hi! @KlemensE , could you specify what do you mean by "source"?

@KlemensE
Copy link

See https://ohmyposh.dev/docs/segments/scm/git under Properties you can find source wich should have the value pwsh to make it work again.

This is because the autocompletion evaluates based on the global variable $GitStatus. This value comes from the Get-GitStatus function. This variable is probably not set correctly.

@simonbondo
Copy link

oh-my-posh checks a global variable, if posh-git is enabled.
See https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.ps1#L189

For my workaround, I simply added the following to my PowerShell profile:

# ... load oh-my-posh
# ... load posh-git
$Global:_ompPoshGit = $true

@Kralizek
Copy link
Author

I'll be honest, I don't understand how omp is involved with the tab suggestion issue.

@simonbondo
Copy link

As I understand, it's because posh-git uses the structure that is stored in the global variable $GitStatus, as mentioned above.
The value of $GitStatus is updated as part of "rendering" the prompt, whenever you change directory.
You can run the command Get-GitStatus from any git repository, to see what that data looks like.

When you also use oh-my-posh at the same time, oh-my-posh is taking over the prompt rendering, and as such, it needs to update the $GitStatus variable for you. posh-git's prompt function is no longer being invoked.

@jfbueno
Copy link

jfbueno commented Nov 7, 2024

@KlemensE's solution worked for me. Thanks a lot. I also cannot understand why is oh-my-posh involved in git completions, but changing that property solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants