Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/powershell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Windows PowerShell

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
strategy:
fail-fast: false
matrix:
os: ['windows-latest']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: install dependencies
shell: powershell
run: |
"Git version: $(git --version)"
"PSVersion: $($PSVersionTable.PSVersion)"
"Host name: $($Host.Name)"

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module Pester -MinimumVersion 5.0.0 -MaximumVersion 5.99.99 -Scope CurrentUser -Force
"Pester: $(Get-Module Pester | % Version)"
- name: run tests
shell: powershell
run: |
Import-Module Pester -PassThru
$ErrorActionPreference = 'Continue'
$res = Invoke-Pester -Path test -Output Detailed -PassThru -ErrorAction SilentlyContinue
if (!$res -or ($res.FailedCount -gt 0)) {
$Error | Format-List * -Force
exit 1
}
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml → .github/workflows/pwsh.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: Test Posh-Git
name: PowerShell Core

on: [push, pull_request]
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
Expand All @@ -20,6 +28,7 @@ jobs:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module Pester -MinimumVersion 5.0.0 -MaximumVersion 5.99.99 -Scope CurrentUser -Force
"Pester: $(Get-Module Pester | % Version)"
- name: run tests
shell: pwsh
run: |
Expand Down
31 changes: 20 additions & 11 deletions src/GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,29 @@ function Get-GitStatus {
'^(?<index>[^#])(?<working>.) (?<path1>.*?)(?: -> (?<path2>.*))?$' {
if ($sw) { dbg "Status: $_" $sw }

$path1 = $matches['path1']

# Even with core.quotePath=false, paths with spaces are wrapped in ""
# https://github.com/git/git/commit/dbfdc625a5aad10c47e3ffa446d0b92e341a7b44
# https://github.com/git/git/commit/f3fc4a1b8680c114defd98ce6f2429f8946a5dc1
if ($path1 -like '"*"') {
$path1 = $path1.Substring(1, $path1.Length - 2)
Comment thread
dahlbyk marked this conversation as resolved.
}

switch ($matches['index']) {
'A' { $null = $indexAdded.Add($matches['path1']); break }
'M' { $null = $indexModified.Add($matches['path1']); break }
'R' { $null = $indexModified.Add($matches['path1']); break }
'C' { $null = $indexModified.Add($matches['path1']); break }
'D' { $null = $indexDeleted.Add($matches['path1']); break }
'U' { $null = $indexUnmerged.Add($matches['path1']); break }
'A' { $null = $indexAdded.Add($path1); break }
'M' { $null = $indexModified.Add($path1); break }
'R' { $null = $indexModified.Add($path1); break }
'C' { $null = $indexModified.Add($path1); break }
'D' { $null = $indexDeleted.Add($path1); break }
'U' { $null = $indexUnmerged.Add($path1); break }
}
switch ($matches['working']) {
'?' { $null = $filesAdded.Add($matches['path1']); break }
'A' { $null = $filesAdded.Add($matches['path1']); break }
'M' { $null = $filesModified.Add($matches['path1']); break }
'D' { $null = $filesDeleted.Add($matches['path1']); break }
'U' { $null = $filesUnmerged.Add($matches['path1']); break }
'?' { $null = $filesAdded.Add($path1); break }
'A' { $null = $filesAdded.Add($path1); break }
'M' { $null = $filesModified.Add($path1); break }
'D' { $null = $filesDeleted.Add($path1); break }
'U' { $null = $filesUnmerged.Add($path1); break }
}
continue
}
Expand Down
5 changes: 5 additions & 0 deletions src/WindowTitle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ function Test-WindowTitleIsWriteable {
# Probe $Host.UI.RawUI.WindowTitle to see if it can be set without errors
try {
$script:OriginalWindowTitle = $Host.UI.RawUI.WindowTitle
if (!$script:OriginalWindowTitle) {
# Set a reasonable title to revert to on uninstall
$Host.UI.RawUI.WindowTitle = 'PowerShell';
$script:OriginalWindowTitle = $Host.UI.RawUI.WindowTitle
}
$newTitle = "${OriginalWindowTitle} "
$Host.UI.RawUI.WindowTitle = $newTitle
$script:HostSupportsSettingWindowTitle = ($Host.UI.RawUI.WindowTitle -eq $newTitle)
Expand Down
35 changes: 16 additions & 19 deletions test/DefaultPrompt.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
BeforeAll {
. $PSScriptRoot\Shared.ps1

[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$SkipWindowTitleTests = !(& $module Test-WindowTitleIsWriteable)
}

Describe 'Default Prompt Tests - NO ANSI' {
BeforeAll {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
Expand Down Expand Up @@ -349,9 +353,7 @@ A test/Foo.Tests.ps1
}
}

# Don't run these tests on the AppVeyor build - the Windows PowerShell host is RemoteHostImplementation which doesn't
# support setting the Window title.
Describe 'Default Prompt WindowTitle Tests' -Skip:($Host.Name -eq 'RemoteHostImplementation') {
Describe 'Default Prompt WindowTitle Tests' -Skip:$SkipWindowTitleTests {
BeforeAll {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$homePath = [regex]::Escape((GetHomePath))
Expand Down Expand Up @@ -396,7 +398,7 @@ M test/Baz.Tests.ps1
& $GitPromptScriptBlock 6>&1
Should -Invoke -ModuleName posh-git -CommandName git -Exactly 1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match $repoAdminRegex
}
else {
Expand All @@ -413,7 +415,7 @@ M test/Baz.Tests.ps1
& $GitPromptScriptBlock 6>&1
Should -Invoke -ModuleName posh-git -CommandName git -Exactly 1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match '^daboss: poshgit == posh-git / master$'
}
else {
Expand All @@ -427,7 +429,7 @@ M test/Baz.Tests.ps1
& $GitPromptScriptBlock 6>&1
Should -Invoke -ModuleName posh-git -CommandName git -Exactly 1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match '^daboss: poshgit == posh-git / master$'
}
else {
Expand Down Expand Up @@ -468,7 +470,7 @@ M test/Baz.Tests.ps1
Set-Location $Home
& $GitPromptScriptBlock 6>&1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match $nonRepoAdminRegex
}
else {
Expand Down Expand Up @@ -498,7 +500,7 @@ M test/Baz.Tests.ps1
Set-Location $Home
& $GitPromptScriptBlock 6>&1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match $nonRepoAdminRegex
}
else {
Expand All @@ -509,7 +511,7 @@ M test/Baz.Tests.ps1
& $GitPromptScriptBlock 6>&1
Should -Invoke -ModuleName posh-git -CommandName git -Exactly 1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match $repoAdminRegex
}
else {
Expand All @@ -519,7 +521,7 @@ M test/Baz.Tests.ps1
Set-Location $Home
& $GitPromptScriptBlock 6>&1
$title = $Host.UI.RawUI.WindowTitle
if (& $module {$IsAdmin}) {
if (& $module { $IsAdmin }) {
$title | Should -Match $nonRepoAdminRegex
}
else {
Expand All @@ -531,17 +533,12 @@ M test/Baz.Tests.ps1
Context 'Removing the posh-git module' {
It 'Correctly reverts the Window Title back to original state' {
Set-Item function:\prompt -Value ([Runspace]::DefaultRunspace.InitialSessionState.Commands['prompt']).Definition
$originalTitle = & $module { $OriginalWindowTitle }
$originalTitle | Should -Not -BeNullOrEmpty

Remove-Module posh-git -Force *>$null
$title = $Host.UI.RawUI.WindowTitle
if ($Host.Name -eq 'RemoteHostImplementation') {
$title | Should -eq $originalTitle
}
elseif ($PSVersionTable.PSVersion.Major -lt 6) {
$title | Should -match '^Windows PowerShell|:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe$'
}
else {
$title | Should -match '^(Administrator: )?(Windows )?PowerShell'
}
$title | Should -eq $originalTitle
Comment thread
dahlbyk marked this conversation as resolved.
}
}
}
Expand Down
Loading