Skip to content

Commit

Permalink
Merge branch 'master' into improve-branch-autocompletion-time
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasHassing authored Mar 27, 2022
2 parents 395f22e + 5c654bf commit c52bdcc
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 230 deletions.
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
}
41 changes: 41 additions & 0 deletions .github/workflows/pwsh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PowerShell Core

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', 'macos-latest', 'ubuntu-latest']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: install dependencies
shell: pwsh
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: pwsh
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
}
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Another popular package manager for Windows is [Scoop](https://scoop.sh/), which
it into your profile:

```powershell
scoop bucket add extras
scoop install posh-git
Add-PoshGitToProfile
```
Expand Down
64 changes: 0 additions & 64 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/CheckRequirements.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (!(Get-Command git -TotalCount 1 -ErrorAction SilentlyContinue)) {
return
}

if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)(?<g4w>\.windows)?') {
if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)(?<g4w>\.windows|\.vfs)?') {
$script:GitVersion = [System.Version]$Matches['ver']

# On Windows, check if Git is not "Git for Windows"
Expand Down
2 changes: 1 addition & 1 deletion src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
$filter = $matches['to']
}

$branches = @(git branch --no-color --list "$filter*" | ForEach-Object { if (($_ -notmatch "^\* \(HEAD detached .+\)$") -and ($_ -match "^[\*\+]?\s*(?<ref>.*)")) { $matches['ref'] } }) +
$branches = @(git branch --no-color --list "$filter*" | ForEach-Object { if (($_ -notmatch "^\* \(HEAD detached .+\)$") -and ($_ -match "^[\*\+]?\s*(?<ref>\S+)(?: -> .+)?")) { $matches['ref'] } }) +
@(git branch --no-color --remotes --list "$filter*" | ForEach-Object { if ($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
@(if ($includeHEAD) { 'HEAD','FETCH_HEAD','ORIG_HEAD','MERGE_HEAD' })

Expand Down
34 changes: 22 additions & 12 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)
}

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 Expand Up @@ -437,7 +446,8 @@ function InDotGitOrBareRepoDir([string][ValidateNotNullOrEmpty()]$GitDir) {
# The latter is more desirable.
$pathInfo = Microsoft.PowerShell.Management\Get-Location
$currentPath = if ($pathInfo.Drive) { $pathInfo.Path } else { $pathInfo.ProviderPath }
$res = $currentPath.StartsWith($GitDir, (Get-PathStringComparison))
$separator = [System.IO.Path]::DirectorySeparatorChar
$res = "$currentPath$separator".StartsWith("$GitDir$separator", (Get-PathStringComparison))
$res
}

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
2 changes: 1 addition & 1 deletion src/posh-git.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ $GitPromptScriptBlock = {
# Write default prompt before suffix text
$prompt += Write-Prompt $settings.DefaultPromptBeforeSuffix.Expand()

# If stopped in the debugger, the prompt needs to indicate that by writing default propmt debug
# If stopped in the debugger, the prompt needs to indicate that by writing default prompt debug
if ((Test-Path Variable:/PSDebugContext) -or [runspace]::DefaultRunspace.Debugger.InBreakpoint) {
$prompt += Write-Prompt $settings.DefaultPromptDebug.Expand()
}
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 '^(Windows )?PowerShell'
}
$title | Should -eq $originalTitle
}
}
}
Expand Down
Loading

0 comments on commit c52bdcc

Please sign in to comment.