diff --git a/test/Get-GitDirectory.Tests.ps1 b/test/Get-GitDirectory.Tests.ps1 index bcbaefacf..191637d48 100644 --- a/test/Get-GitDirectory.Tests.ps1 +++ b/test/Get-GitDirectory.Tests.ps1 @@ -35,44 +35,25 @@ Describe 'Get-GitDiretory Tests' { Context 'Test worktree' { BeforeEach { [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')] - $origPath = Get-Location - $temp = [System.IO.Path]::GetTempPath() - $repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName()) - $worktreePath = Join-Path $temp ([IO.Path]::GetRandomFileName()) - - &$gitbin init $repoPath - Set-Location $repoPath - - # Git rid of Git warnings about configuring user for the commit we do below - &$gitbin config user.email "you@example.com" - &$gitbin config user.name "Pester User" - - 'foo' > ./README.md - &$gitbin add ./README.md - # Quoting is a hack due to our use of the global:git function and how it converts args for invoke-expression - &$gitbin commit -m "`"initial commit.`"" + $repoPath = NewGitTempRepo -MakeInitialCommit + $worktree = [IO.Path]::GetRandomFileName() + $worktreePath = Split-Path $repoPath -Parent + $worktreePath = Join-Path $worktreePath $worktree - if (Test-Path $worktreePath) { - Remove-Item $worktreePath -Recurse -Force - } New-Item $worktreePath -ItemType Directory > $null &$gitbin worktree add -b test-worktree $worktreePath master 2>$null } AfterEach { - Set-Location $origPath - if (Test-Path $repoPath) { - Remove-Item $repoPath -Recurse -Force - } - if (Test-Path $worktreePath) { + RemoveGitTempRepo $repoPath + if ($worktreePath -and (Test-Path $worktreePath)) { Remove-Item $worktreePath -Recurse -Force } } It 'Returns the correct dir when under a worktree' { Set-Location $worktreePath - $worktreeBaseName = Split-Path $worktreePath -Leaf $path = GetMacOSAdjustedTempPath $repoPath - Get-GitDirectory | Should -BeExactly (MakeGitPath $path\.git\worktrees\$worktreeBaseName) + Get-GitDirectory | Should -BeExactly (MakeGitPath $path\.git\worktrees\$worktree) } } diff --git a/test/Shared.ps1 b/test/Shared.ps1 index 036e3a6b8..16d0c32b1 100644 --- a/test/Shared.ps1 +++ b/test/Shared.ps1 @@ -137,6 +137,8 @@ function NewGitTempRepo([switch]$MakeInitialCommit) { if ($MakeInitialCommit) { &$gitbin config user.email "spaceman.spiff@appveyor.com" &$gitbin config user.name "Spaceman Spiff" + &$gitbin config commit.gpgSign "false" + 'readme' | Out-File ./README.md -Encoding ascii &$gitbin add ./README.md *>$null &$gitbin commit -m "initial commit." *>$null diff --git a/test/TabExpansion.Tests.ps1 b/test/TabExpansion.Tests.ps1 index 4138893e4..30b33f689 100644 --- a/test/TabExpansion.Tests.ps1 +++ b/test/TabExpansion.Tests.ps1 @@ -232,16 +232,16 @@ Describe 'TabExpansion Tests' { [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')] $repoPath = NewGitTempRepo -MakeInitialCommit - $addedAliases = @() + $addedAliases = @{} function Add-GlobalTestAlias($Name, $Value) { if (!(&$gitbin config --global "alias.$Name")) { &$gitbin config --global "alias.$Name" $Value - $addedAliases += $Name + $addedAliases[$Name] = $Value } } } AfterAll { - $addedAliases | Where-Object { $_ } | ForEach-Object { + $addedAliases.Keys | ForEach-Object { &$gitbin config --global --unset "alias.$_" 2>$null }