Skip to content

Commit

Permalink
Rename -TargetRepo to -Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
leojonathanoh committed Nov 27, 2023
1 parent 3befd72 commit 3f20cf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions Generate-GitBranches.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Describe "Generate-GitBranches.ps1" {
It "Parameter validation" {
{
cd $PSScriptRoot
& ./Generate-GitBranches.ps1 -TargetRepo '' -ErrorAction Stop
& ./Generate-GitBranches.ps1 -Repo '' -ErrorAction Stop
} | Should -Throw
}

Expand All @@ -38,9 +38,9 @@ Describe "Generate-GitBranches.ps1" {
It "Creates and updates branches of a same repo (dry-run) " {
$currentRef = git rev-parse --short HEAD
if ($LASTEXITCODE) { throw }
& ./Generate-GitBranches.ps1 -TargetRepo . -Pull -ErrorAction Stop -WhatIf 6>$null # Create
& ./Generate-GitBranches.ps1 -Repo . -Pull -ErrorAction Stop -WhatIf 6>$null # Create
git checkout $currentRef
& ./Generate-GitBranches.ps1 -TargetRepo . -Pull -ErrorAction Stop -WhatIf 6>$null # Update
& ./Generate-GitBranches.ps1 -Repo . -Pull -ErrorAction Stop -WhatIf 6>$null # Update

cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
Expand All @@ -50,9 +50,9 @@ Describe "Generate-GitBranches.ps1" {
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
& ./Generate-GitBranches.ps1 -Repo . -Pull -ErrorAction Stop 6>$null # Create
git checkout $currentRef
& ./Generate-GitBranches.ps1 -TargetRepo . -Pull -ErrorAction Stop 6>$null # Update
& ./Generate-GitBranches.ps1 -Repo . -Pull -ErrorAction Stop 6>$null # Update

cd $sameRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
Expand Down Expand Up @@ -89,17 +89,17 @@ Describe "Generate-GitBranches.ps1" {
}

It "Creates and updates branches of a different repo (dry-run)" {
& $sourceRepo/Generate-GitBranches.ps1 -TargetRepo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Create
& $sourceRepo/Generate-GitBranches.ps1 -TargetRepo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Update
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null -WhatIf # Update

cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
$branches.Count | Should -Be 0
}

It "Creates and updates branches of a different repo" {
& $sourceRepo/Generate-GitBranches.ps1 -TargetRepo $differentRepo -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -TargetRepo $differentRepo -ErrorAction Stop 6>$null # Update
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null # Create
& $sourceRepo/Generate-GitBranches.ps1 -Repo $differentRepo -ErrorAction Stop 6>$null # Update

cd $differentRepo
$branches = git branch | % { $_.Replace('*', '').Trim() } | ? { $_ -match '^steam-' }
Expand Down
20 changes: 10 additions & 10 deletions Generate-GitBranches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# 3. To build a game, checkout to its branch, edit .env, mutate .trigger, commit and push
# Examples:
# # Create branches for all games (dry-run)
# ./Generate-GitBranches.ps1 -TargetRepo . -Pull -WhatIf
# ./Generate-GitBranches.ps1 -Repo . -Pull -WhatIf
#
# # Create branches for all games
# ./Generate-GitBranches.ps1 -TargetRepo . -Pull
# ./Generate-GitBranches.ps1 -Repo . -Pull
#
# # Create branches for specific game
# ./Generate-GitBranches.ps1 -TargetRepo . -Pull -GameEngine srcds -Game csgo
# ./Generate-GitBranches.ps1 -Repo . -Pull -GameEngine srcds -Game csgo
#
# # Update branches for all games
# ./Generate-GitBranches.ps1 -TargetRepo . -Pull -Push
# ./Generate-GitBranches.ps1 -Repo . -Pull -Push
#
# # Update branches for specific game
# ./Generate-GitBranches.ps1 -TargetRepo . -Pull -Push -GameEngine srcds -Game csgo
# ./Generate-GitBranches.ps1 -Repo . -Pull -Push -GameEngine srcds -Game csgo
#
[CmdletBinding(SupportsShouldProcess)]
param(
# Target repo path
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$TargetRepo
[string]$Repo
,
# Whether to pull changes from remote repo before creating / updating branches
[switch]$Pull
Expand Down Expand Up @@ -125,13 +125,13 @@ try {
}
$sourceRef = { git rev-parse --abbrev-ref HEAD } | Execute-Command
try {
$TargetRepo = { cd $TargetRepo; git rev-parse --show-toplevel; cd - } | Execute-Command -WhatIf:$false # Execute this even if -WhatIf is passed
$Repo = { cd $Repo; git rev-parse --show-toplevel; cd - } | Execute-Command -WhatIf:$false # Execute this even if -WhatIf is passed
}catch {
throw "$TargetRepo is not a git repo. Create a repo using: git init -b master"
throw "$Repo is not a git repo. Create a repo using: git init -b master"
}
$isSameRepo = if ($TargetRepo -eq $sourceRepo) { $true } else { $false }
$isSameRepo = if ($Repo -eq $sourceRepo) { $true } else { $false }

Push-Location $TargetRepo
Push-Location $Repo
foreach ($g in $games) {
$branch = "$( $g['game_platform'] )-$( $g['game_engine'] )-$( $g['game'] )"

Expand Down

0 comments on commit 3f20cf8

Please sign in to comment.