Skip to content
Open
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
33 changes: 7 additions & 26 deletions test/Get-GitDirectory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/Shared.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down