diff --git a/Generate-GitBranches.Tests.ps1 b/Generate-GitBranches.Tests.ps1 index b995b8da..2dc48626 100644 --- a/Generate-GitBranches.Tests.ps1 +++ b/Generate-GitBranches.Tests.ps1 @@ -47,7 +47,7 @@ Describe "Generate-GitBranches.ps1" { $branches.Count | Should -Be 0 } - It "Creates and updates branches of this same repo" { + It "Creates and updates branches of a same repo" { $currentRef = git rev-parse --short HEAD if ($LASTEXITCODE) { throw } & ./Generate-GitBranches.ps1 -TargetRepo . -Pull -ErrorAction Stop 6>$null # Create diff --git a/Generate-GitBranches.ps1 b/Generate-GitBranches.ps1 index 424d56e4..0645e6df 100644 --- a/Generate-GitBranches.ps1 +++ b/Generate-GitBranches.ps1 @@ -117,11 +117,16 @@ function Get-EnvFileKv ($file, $branch) { # Create new branch, remove all files except .git, create .trigger file, create .gitlab-ci.yml, commit files try { - $sourceRepo = { cd $PSScriptRoot; git rev-parse --show-toplevel; cd - } | Execute-Command -ErrorAction SilentlyContinue -WhatIf:$false - if ($LASTEXITCODE) { throw "$PSScriptRoot is not a git repo" } - - $TargetRepo = { cd $TargetRepo; git rev-parse --show-toplevel; cd - } | Execute-Command -ErrorAction SilentlyContinue -WhatIf:$false - if ($LASTEXITCODE) { throw "$TargetRepo is not a git repo" } + try { + $sourceRepo = { cd $PSScriptRoot; git rev-parse --show-toplevel; cd - } | Execute-Command -WhatIf:$false # -WhatIf:$false means execute this even if -WhatIf is passed + }catch { + throw "$PSScriptRoot is not a git repo" + } + try { + $TargetRepo = { cd $TargetRepo; git rev-parse --show-toplevel; cd - } | Execute-Command -WhatIf:$false # -WhatIf:$false means execute this even if -WhatIf is passed + }catch { + throw "$TargetRepo is not a git repo" + } $isSameRepo = if ($TargetRepo -eq $sourceRepo) { $true } else { $false }