Skip to content

Commit 151ce6c

Browse files
authored
Merge pull request #893 from dahlbyk/unignore-github-path
Fix ignoring .github path
2 parents 5c9ca47 + e3daee8 commit 151ce6c

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

src/GitUtils.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ function InDotGitOrBareRepoDir([string][ValidateNotNullOrEmpty()]$GitDir) {
446446
# The latter is more desirable.
447447
$pathInfo = Microsoft.PowerShell.Management\Get-Location
448448
$currentPath = if ($pathInfo.Drive) { $pathInfo.Path } else { $pathInfo.ProviderPath }
449-
$res = $currentPath.StartsWith($GitDir, (Get-PathStringComparison))
449+
$separator = [System.IO.Path]::DirectorySeparatorChar
450+
$res = "$currentPath$separator".StartsWith("$GitDir$separator", (Get-PathStringComparison))
450451
$res
451452
}
452453

test/Get-GitStatus.Tests.ps1

+80
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ Describe 'Get-GitStatus Tests' {
2424
$status = Get-GitStatus
2525
Should -Invoke -ModuleName posh-git -CommandName git -Exactly 1
2626
$status.Branch | Should -Be "rkeithill/more-status-tests"
27+
$status.HasIndex | Should -Be $false
28+
$status.HasUntracked | Should -Be $false
29+
$status.HasWorking | Should -Be $false
30+
$status.Working.Added.Count | Should -Be 0
31+
$status.Working.Deleted.Count | Should -Be 0
32+
$status.Working.Modified.Count | Should -Be 0
33+
$status.Working.Unmerged.Count | Should -Be 0
34+
$status.Index.Added.Count | Should -Be 0
35+
$status.Index.Deleted.Count | Should -Be 0
36+
$status.Index.Modified.Count | Should -Be 0
37+
$status.Index.Unmerged.Count | Should -Be 0
2738
}
2839

2940

@@ -428,4 +439,73 @@ U test/Unmerged.Tests.ps1
428439
$status.Index.Unmerged[0] | Should -Be "test/Unmerged.Tests.ps1"
429440
}
430441
}
442+
443+
Context 'In .git' {
444+
BeforeEach {
445+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
446+
$repoPath = NewGitTempRepo
447+
}
448+
AfterEach {
449+
Set-Location $PSScriptRoot
450+
RemoveGitTempRepo $repoPath
451+
}
452+
453+
It('Does not have files') {
454+
New-Item "$repoPath/test.txt" -ItemType File
455+
456+
$status = Get-GitStatus
457+
$status.HasUntracked | Should -Be $true
458+
$status.HasWorking | Should -Be $true
459+
$status.Working.Added.Count | Should -Be 1
460+
461+
Set-Location "$repoPath/.git" -ErrorAction Stop
462+
463+
$status = Get-GitStatus
464+
$status.HasUntracked | Should -Be $false
465+
$status.HasWorking | Should -Be $false
466+
$status.Working.Added.Count | Should -Be 0
467+
468+
Set-Location "$repoPath/.git/refs" -ErrorAction Stop
469+
470+
$status = Get-GitStatus
471+
$status.HasUntracked | Should -Be $false
472+
$status.HasWorking | Should -Be $false
473+
$status.Working.Added.Count | Should -Be 0
474+
}
475+
}
476+
477+
Context 'In .github' {
478+
BeforeEach {
479+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
480+
$repoPath = NewGitTempRepo
481+
New-Item -Type Directory -Force "$repoPath/.github/workflows"
482+
}
483+
AfterEach {
484+
Set-Location $PSScriptRoot
485+
RemoveGitTempRepo $repoPath
486+
}
487+
488+
It('Files are not ignored') {
489+
New-Item "$repoPath/test.txt" -ItemType File
490+
491+
$status = Get-GitStatus
492+
$status.HasUntracked | Should -Be $true
493+
$status.HasWorking | Should -Be $true
494+
$status.Working.Added.Count | Should -Be 1
495+
496+
Set-Location "$repoPath/.github" -ErrorAction Stop
497+
498+
$status = Get-GitStatus
499+
$status.HasUntracked | Should -Be $true
500+
$status.HasWorking | Should -Be $true
501+
$status.Working.Added.Count | Should -Be 1
502+
503+
Set-Location "$repoPath/.github/workflows" -ErrorAction Stop
504+
505+
$status = Get-GitStatus
506+
$status.HasUntracked | Should -Be $true
507+
$status.HasWorking | Should -Be $true
508+
$status.Working.Added.Count | Should -Be 1
509+
}
510+
}
431511
}

test/Shared.ps1

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function GetHomePath() {
6666
}
6767

6868
function GetHomeRelPath([string]$Path) {
69-
if (!$Path.StartsWith($Home)) {
69+
$separator = [System.IO.Path]::DirectorySeparatorChar
70+
if (!("$Path$separator".StartsWith("$Home$separator"))) {
7071
# Path not under $Home
7172
return $Path
7273
}
@@ -87,7 +88,8 @@ function GetGitRelPath([string]$Path) {
8788
# Up one level from `.git`
8889
$gitPath = Split-Path $gitPath -Parent
8990

90-
if (!$Path.StartsWith($gitPath)) {
91+
$separator = [System.IO.Path]::DirectorySeparatorChar
92+
if (!"$Path$separator".StartsWith("$gitPath$separator")) {
9193
# Path not under $gitPath
9294
return $Path
9395
}

0 commit comments

Comments
 (0)