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

PoshGit / ugit Compatibility Issues

Open StartAutomating opened this issue 1 year ago • 5 comments

System Details

  • posh-git version/path: 1.1.0 ~\Documents\PowerShell\Modules\posh-git\1.1.0
  • PowerShell version: 7.2.5
  • git version 2.35.1.windows.2
  • OS: Microsoft Windows NT 10.0.22000.0

Issue Description

posh-git has a compatibility issue with ugit.

This is because ugit overrides git with a PowerShell command.

While this does support any number of arguments, PowerShell can get confused when dealing with short argument names.

Thus line 331 in Get-GitStatus blows up the prompt.

The solution for this works just fine if ugit is loaded or not.

Quote the single character arguments:

git --no-optional-locks '-c' core.quotepath=false '-c' color.status=false status $untrackedFilesOption --short --branch 2>$null

Since posh-git is already very useful, but doesn't return git naturally as objects, it makes sense for both modules to work together in concert.

StartAutomating avatar Jul 09 '22 01:07 StartAutomating

Since posh-git is already very useful, but doesn't return git naturally as objects, it makes sense for both modules to work together in concert.

Agree! I'll ship a new version as soon as I can get a few lingering PRs merged.

dahlbyk avatar Jul 14 '22 00:07 dahlbyk

Cool!

It occurs to me that you might rely on git output being text in other places. So while this might have gotten rid of the most obvious breaking change, it's possible there are others.

It would be fairly trivial for you to save $executionContext.SessionState.InvokeCommand('git','Application') into a variable, and call that explicitly in your scripts (it's the trick ugit is doing under the hood).

Doing this should prevent any future hijinks.

StartAutomating avatar Jul 14 '22 00:07 StartAutomating

It would be fairly trivial for you to save $executionContext.SessionState.InvokeCommand('git','Application') into a variable

I assume you mean InvokeCommand.GetCommand('git', 'Application'). Would this be more efficient than Get-Command git -CommandType Application?

dahlbyk avatar Jul 14 '22 00:07 dahlbyk

Sorry for the delay in response (and the typo).

Yes, $executionContext is faster than Get-Command. I'll add a Benchmark on this to Benchpress.

On my box, here's what the results were:

Technique Time RelativeSpeed Throughput
$executionContext 00:00:00.198679 1x 503.32/s
Get-Command 00:00:00.266019 1.34x 375.91/s

StartAutomating avatar Jul 16 '22 20:07 StartAutomating

It's so cool to see two awesome projects collaborating together! :smile: I'm looking forward to when this fix will be released as it is affecting me as well right now.

charltonstanley avatar Oct 06 '22 15:10 charltonstanley