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

After installing Git "rc" version, PowerShell reports an error #845

Closed
DustinWin opened this issue Mar 14, 2021 · 4 comments · Fixed by #885
Closed

After installing Git "rc" version, PowerShell reports an error #845

DustinWin opened this issue Mar 14, 2021 · 4 comments · Fixed by #885

Comments

@DustinWin
Copy link

Git version: 2.31.0-rc2 (all rc version)
Operating system version: Windows 10 21H1
PowerShell version: comes with the system
oh-my-posh version: 3.111.2
posh-git version: 1.0.0
Steps to reproduce:

  1. Run PowerShell as an administrator and run the following command:
Set-ExecutionPolicy RemoteSigned
Install-Module posh-git
Install-Module oh-my-posh
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme PowerLine
  1. Enter the folder C:\Users\ [your username] \Documents\WindowsPowerShell, edit the text document, and enter the following:
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme PowerLine

And save as Microsoft.PowerShell_profile.ps1
3. Close PowerShell, and open PowerShell again
Expected results:
PowerShell will not report errors
Actual results:
PowerShell reports an error, and the content of the error:
Warning: You appear to have an unsupported Git distribution; setting $GitPromptSettings.AnsiConsole = $false. posh-git recommends Git for Windows.
111055583-49ac3600-84b2-11eb-879b-b244d468566f
Remarks:
If you install Git v2.30.2 version, no error will be reported. I installed the 2.31.0 rc1, 2.31.0 rc0, and 2.30.0 rc2 versions, and all encountered this problem. I installed the 2.30.1 and 2.30.2 version again and did not encounter this problem. After I reported this problem in Git, I was told that it was a posh-git problem. Please see: git-for-windows/git#3111 (comment)

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 14, 2021

The regex use to validate the Git version lives here:

if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)(?<g4w>\.windows)?') {

The warning is from past issues with folks using the Cygwin build of Git which doesn't include .windows in its --version.

You can set $Env:POSHGIT_CYGWIN_WARNING = "off" to disable the warning, or we can try to figure out a better way to identify Git for Windows vs other builds.

if (!$Env:POSHGIT_CYGWIN_WARNING) {
Write-Warning 'You appear to have an unsupported Git distribution; setting $GitPromptSettings.AnsiConsole = $false. posh-git recommends Git for Windows.'
}

@dscho
Copy link
Contributor

dscho commented Mar 14, 2021

 if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)(?<g4w>\.windows)?') {

Extending this in the following way seems to fix the issue for me:

diff a/src/CheckRequirements.ps1 b/src/CheckRequirements.ps1
--- a/src/CheckRequirements.ps1
+++ b/src/CheckRequirements.ps1 
@@ -10,+3 +10,+3 @@
 
-if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)(?<g4w>\.windows)?') {
+if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)(?<g4w>(\.rc\d+)?\.windows)?') {
     $script:GitVersion = [System.Version]$Matches['ver']

@DustinWin can you verify that this works for you? If so, would you mind opening the PR?

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 15, 2021

Can you think of a reason not to make this morning forgiving, e.g. .*(?<g4w>\.windows)?')?

@dscho
Copy link
Contributor

dscho commented Mar 15, 2021

Can you think of a reason not to make this morning forgiving, e.g. .*(?<g4w>\.windows)?')?

That should work!

dscho added a commit to dscho/posh-git that referenced this issue Jan 17, 2022
The version check was a bit too tight.

This fixes dahlbyk#845.

Note: it was suggested in that ticket to use a laxer version check, but
that looks as if it might have unwanted consequences, so let's give just
an inch for starters.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
KatherineGirona added a commit to KatherineGirona/posh-git that referenced this issue Oct 11, 2022
The version check was a bit too tight.

This fixes dahlbyk/posh-git#845.

Note: it was suggested in that ticket to use a laxer version check, but
that looks as if it might have unwanted consequences, so let's give just
an inch for starters.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
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

Successfully merging a pull request may close this issue.

3 participants