From 1526eb1bcf9168229cb705f33b4a1011a1eeca2a Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Fri, 29 Aug 2025 00:47:59 +1000 Subject: [PATCH] getpunk script fix rename/move on windows --- getpunk.cmd | 5 ++++- src/scriptapps/getpunk.bash | 1 + src/scriptapps/getpunk.ps1 | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/getpunk.cmd b/getpunk.cmd index 830d0096..34c07761 100644 --- a/getpunk.cmd +++ b/getpunk.cmd @@ -920,6 +920,7 @@ $launchdir = Get-Location #store original CWD $scriptfolder = Resolve-Path (Split-Path -Path $PSCommandPath -Parent) $punkfolder = "" $scriptroot = "$([System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath))" +$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) { Write-Host "The git command doesn't seem to be available. Will attempt to install using winget." @@ -1018,10 +1019,12 @@ if (-not(Test-Path -Path (Join-Path -Path $punkfolder -ChildPath ".git") -PathTy git fetch origin if (($launchdir.Path) -eq ($scriptfolder.Path)) { if (Test-Path -Path "${scriptroot}.cmd") { - Rename-Item -Path "${scriptroot}.cmd" -NewName "${scriptroot}.cmd.lastrun" -Force + #rename-item won't allow overwriting existing target file + Move-Item -Path "${scriptroot}.cmd" -Destination "${scriptroot}.cmd.lastrun" -Force } } git pull $git_upstream master +git checkout $scriptroot.cmd git branch --set-upstream-to=origin/master master Set-Location $launchdir #restore original CWD diff --git a/src/scriptapps/getpunk.bash b/src/scriptapps/getpunk.bash index a9a33f65..6f9307aa 100644 --- a/src/scriptapps/getpunk.bash +++ b/src/scriptapps/getpunk.bash @@ -81,6 +81,7 @@ if [[ "$punkfolder" == "$scriptdir" ]]; then fi fi git pull $git_upstream master +git checkout $scriptroot.cmd git branch --set-upstream-to=origin/master master cd $launchdir #restore original CWD diff --git a/src/scriptapps/getpunk.ps1 b/src/scriptapps/getpunk.ps1 index c3094949..3724dff9 100644 --- a/src/scriptapps/getpunk.ps1 +++ b/src/scriptapps/getpunk.ps1 @@ -11,6 +11,7 @@ $launchdir = Get-Location #store original CWD $scriptfolder = Resolve-Path (Split-Path -Path $PSCommandPath -Parent) $punkfolder = "" $scriptroot = "$([System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath))" +$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) { Write-Host "The git command doesn't seem to be available. Will attempt to install using winget." @@ -109,10 +110,12 @@ if (-not(Test-Path -Path (Join-Path -Path $punkfolder -ChildPath ".git") -PathTy git fetch origin if (($launchdir.Path) -eq ($scriptfolder.Path)) { if (Test-Path -Path "${scriptroot}.cmd") { - Rename-Item -Path "${scriptroot}.cmd" -NewName "${scriptroot}.cmd.lastrun" -Force + #rename-item won't allow overwriting existing target file + Move-Item -Path "${scriptroot}.cmd" -Destination "${scriptroot}.cmd.lastrun" -Force } } git pull $git_upstream master +git checkout $scriptroot.cmd git branch --set-upstream-to=origin/master master Set-Location $launchdir #restore original CWD