Skip to content

Commit

Permalink
Fix: Fix Generate-GitBranches.ps1 -Pull behavior to track remote br…
Browse files Browse the repository at this point in the history
…anch if local branch does not exist (#193)
  • Loading branch information
leojonathanoh authored Feb 4, 2025
1 parent 96e75ff commit 5966e45
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Generate-GitBranches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,34 @@ try {

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

{ git checkout -f master } | Execute-Command
if ($Pull) {
{ git fetch "$Remote" } | Execute-Command
{ git pull "$Remote" master } | Execute-Command
}

$branch = "$( $g['game_platform'] )-$( $g['game_engine'] )-$( $g['game'] )"
$existingBranch = { git rev-parse --verify $branch 2>$null } | Execute-Command -ErrorAction SilentlyContinue
if ($existingBranch) {
"Updating branch '$branch'" | Write-Host -ForegroundColor Green
if ($Pull) {
{ git fetch "$Remote" } | Execute-Command
$existingRemoteBranch = { git rev-parse --verify "$Remote/$branch" 2>$null } | Execute-Command -ErrorAction SilentlyContinue
if ($existingRemoteBranch) {
if ($Pull) {
$existingRemoteBranch = { git rev-parse --verify "$Remote/$branch" 2>$null } | Execute-Command -ErrorAction SilentlyContinue
if ($existingRemoteBranch) {
"Updating branch '$branch'" | Write-Host -ForegroundColor Green
if ($existingBranch) {
{ git branch -f $branch "$Remote/$branch" } | Execute-Command
}else {
{ git checkout --track "$Remote/$branch" } | Execute-Command
}
}else {
throw "No existing remote branch $Remote/$branch for -Pull to --track"
}
{ git checkout -f $branch } | Execute-Command
}else {
"Creating new branch '$branch'" | Write-Host -ForegroundColor Green
{ git checkout -b $branch } | Execute-Command
if ($existingBranch) {
"Updating branch '$branch'" | Write-Host -ForegroundColor Green
{ git checkout -f $branch } | Execute-Command
}else {
"Creating new branch '$branch'" | Write-Host -ForegroundColor Green
{ git checkout -b $branch } | Execute-Command
}
}

"Removing all tracked files" | Write-Host -ForegroundColor Green
Expand Down

0 comments on commit 5966e45

Please sign in to comment.