dahlbyk / posh-git

A PowerShell environment for Git
http://dahlbyk.github.io/posh-git/
MIT License
7.62k stars 802 forks source link

Powershell 7.3.0 does not show posh-git status bar #932

Closed alexanderwallau closed 1 year ago

alexanderwallau commented 1 year ago

System Details

Issue Description

I am experiencing a problem with Powershell 7.30 in windows terminal (ver 1.15.2875.0) specifically that the status bar oes not appear in folders with git repository. Troubleshooting done so far:

My suspision would be that the methods to add the status bar to the PowerShell promt have changed because of the autotabbing for git working as usual.

juliank commented 1 year ago

I can confirm the same issue with the same versions mentioned above.

My temporary workaround is to use the Windows PowerShell profile (being version 5.1.19041) within Windows Terminal, instead of PowerShell (Core). The posh-git status bar shows as expected there.

lewis-hu commented 1 year ago

When I turned on tracing, I found that this line is not setting the status variable at all: https://github.com/dahlbyk/posh-git/blob/b8c1f17262263072e10bfe5067c62ed64ad12e64/src/GitUtils.ps1#L331

tsposato commented 1 year ago

Same issue here with PowerShell 7.3.0

seanblue commented 1 year ago

I'm using PowerShell 7.3.1 and seeing the same issue.

tcomben commented 1 year ago

I think I found a workaround. If you replace lines 326-331 in ./src/GitUtils.ps1 with the code below, it works. For some reason, I needed to get rid of the "2" after the branch argument in the status command, as well as the ">$null". Git doesn't like having an empty string in the pathspec argument either, hence not including $untrackedFilesOption when it's empty.

https://github.com/dahlbyk/posh-git/blob/b8c1f17262263072e10bfe5067c62ed64ad12e64/src/GitUtils.ps1#L326-L331

$psMajor = $($PSVersionTable.PSVersion.Major) -as [int]
$psMinor = $($PSVersionTable.PSVersion.Minor) -as [int]

$status = $null
$untrackedFilesOption = if ($settings.UntrackedFilesMode) { "-u$($settings.UntrackedFilesMode)" } else { "" }
if (($psMajor -ge 7 -and $psMinor -ge 3) -or $psMajor -gt 7) {
    if ($untrackedFilesOption.Length -gt 0) {
        $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status $untrackedFilesOption --short --branch }
    }
    else {
        $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status --short --branch }
    }
}
else {
    $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status $untrackedFilesOption --short --branch 2>$null }
}
inspektor99 commented 1 year ago

I think I found a workaround. If you replace lines 326-331 in ./src/GitUtils.ps1 with the code below, it works. For some reason, I needed to get rid of the "2" after the branch argument in the status command, as well as the ">$null". Git doesn't like having an empty string in the pathspec argument either, hence not including $untrackedFilesOption when it's empty.

https://github.com/dahlbyk/posh-git/blob/b8c1f17262263072e10bfe5067c62ed64ad12e64/src/GitUtils.ps1#L326-L331

$psMajor = $($PSVersionTable.PSVersion.Major) -as [int]
$psMinor = $($PSVersionTable.PSVersion.Minor) -as [int]

$status = $null
$untrackedFilesOption = if ($settings.UntrackedFilesMode) { "-u$($settings.UntrackedFilesMode)" } else { "" }
if (($psMajor -ge 7 -and $psMinor -ge 3) -or $psMajor -gt 7) {
    if ($untrackedFilesOption.Length -gt 0) {
        $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status $untrackedFilesOption --short --branch }
    }
    else {
        $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status --short --branch }
    }
}
else {
    $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status $untrackedFilesOption --short --branch 2>$null }
}

Confirmed fixed in PS 7.3.x, also works in previous versions.

My code replacement in GitUtils.ps1 was slightly different:

Replace this line (236ish) with @tcomben s fix:

$status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status $untrackedFilesOption --short --branch 2>$null }
lewis-hu commented 1 year ago

I realised I encountered this issue because I installed poshgit using chocolatey, which, according to https://community.chocolatey.org/packages/poshgit, it's latest version stalled at 0.7.3.1.

Installing latest via

git clone https://github.com/dahlbyk/posh-git.git && .\install.ps1

fixed it for me.

Reference: