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

importing ugit module breaks git prompt #260

Open
aldrichtr opened this issue Mar 26, 2024 · 4 comments
Open

importing ugit module breaks git prompt #260

aldrichtr opened this issue Mar 26, 2024 · 4 comments

Comments

@aldrichtr
Copy link

The module posh-git provides the ability to show the status of the current git repository in the prompt.

# current prompt

[17472]\projects\testproject [main +1 ~0 -0 | +5 ~0 -0 !]

PS> import-module ugit

# after importing ugit (git status no longer appears in prompt)

[17472]\projects\testproject

PS> remove-module ugit

# removing the module shows the git prompt again

[17472]\projects\testproject [main +1 ~0 -0 | +5 ~0 -0 !]

PS>

The issue is that posh-git uses git status and regexen to build the prompt.

Perhaps ugit could provide a replacement for posh-git\Write-VcsStatus ?

@StartAutomating
Copy link
Owner

@aldrichtr this is actually posh-git's problem, and they are fixing it (as I understand it, the fix is already in master, but there is not yet a release).

If you want to understand more about why, let me know.

@aldrichtr
Copy link
Author

I may have it wrong, but I think posh-git gets it's status from the output of the git status command. When uGit is loaded, this command is remapped to Use-Git.

On my system I get:

[26704]…\projects\testproject [main +1 ~0 -0 | +5 ~0 -0 !]
PS> get-command git

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     git.exe                                            2.44.0.1   C:\Program Files\Git\cmd\git.exe

[26704]…\projects\testproject [main +1 ~0 -0 | +5 ~0 -0 !]
PS> Import-Module ugit
[26704]…\projects\testproject
PS> get-command git

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           git -> Use-Git                                     0.4.2      ugit

I'm thinking that any module / function that uses the output of git will have the same issue, right?

@StartAutomating
Copy link
Owner

@aldrichtr that's right.

Each tool that wants to use both should reference the git application directly (not just any command named git).

They could also choose to simply require ugit and depend on its output (which contains the original text beneath, if they still need to parse it directly)

The alternative would be callstack peeking and blacklisting certain commands in the callstack, which creates a game of whack-a-mole in ugit's codebase, instead of a simple fix in any other codebase (it also creates a reporting gap).

Out of curiosity, what parts of posh-git do you use, aside from the prompt?

@mconnew
Copy link

mconnew commented Aug 14, 2024

I'm getting an actual error from posh-git, and this problem I believe does exist in ugit. I get the following error as soon as I import ugit:

[PoshGitVcsPrompt error: Cannot bind parameter because parameter 'c' is specified more than once. To provide multiple values to parameters that can accept multiple values, use the array syntax. For example, "-parameter value1,value2,value3".]

I tracked this down to an error being thrown by Use-Git. The error is caused from parsing the git command line that posh-git uses. The start of the command is git --no-optional-locks -c core.quotepath=false -c color.s. The problem is -c is being passed on the command line multiple times. Outside of posh-git's usage (I know you believe they shouldn't use the aliased git command and instead make sure they directly call git.exe, but so I'm addressing that now), if you can pass a parameter multiple times to git.exe, and Use-Git is intended as a transparent replacement, any repeated parameters specified by a user will cause a failure.

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

3 participants