Update clean-repo.ps1 and pull-repo.ps1

This commit is contained in:
Markus Fleschutz 2023-03-28 08:43:16 +02:00
parent 035bafb668
commit cb76629c20
2 changed files with 9 additions and 9 deletions

View File

@ -1,11 +1,11 @@
<# <#
.SYNOPSIS .SYNOPSIS
Clean a repository Cleans a repo
.DESCRIPTION .DESCRIPTION
This PowerShell script deletes all untracked files and folders in a Git repository (including submodules). This PowerShell script deletes all untracked files and folders in a local Git repository (including submodules).
NOTE: To be used with care! This cannot be undone! NOTE: To be used with care! This cannot be undone!
.PARAMETER RepoDir .PARAMETER RepoDir
Specifies the path to the Git repository Specifies the file path to the local Git repository
.EXAMPLE .EXAMPLE
PS> ./clean-repo C:\MyRepo PS> ./clean-repo C:\MyRepo
.LINK .LINK
@ -27,7 +27,7 @@ try {
"⏳ (2/4) Checking Git repository... 📂$RepoDirName" "⏳ (2/4) Checking Git repository... 📂$RepoDirName"
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder '$RepoDir' - maybe a typo or missing folder permissions?" } if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder '$RepoDir' - maybe a typo or missing folder permissions?" }
"⏳ (3/4) Removing untracked files in repository..." "⏳ (3/4) Removing untracked files in the repository..."
& git -C "$RepoDir" clean -xfd -f # to delete all untracked files in the main repo & git -C "$RepoDir" clean -xfd -f # to delete all untracked files in the main repo
if ($lastExitCode -ne "0") { if ($lastExitCode -ne "0") {
Write-Warning "'git clean' failed with exit code $lastExitCode, retrying once..." Write-Warning "'git clean' failed with exit code $lastExitCode, retrying once..."
@ -35,12 +35,12 @@ try {
if ($lastExitCode -ne "0") { throw "'git clean' failed with exit code $lastExitCode" } if ($lastExitCode -ne "0") { throw "'git clean' failed with exit code $lastExitCode" }
} }
"⏳ (4/4) Removing untracked files in submodules..." "⏳ (4/4) Removing untracked files in the submodules..."
& git -C "$RepoDir" submodule foreach --recursive git clean -xfd -f # to delete all untracked files in the submodules & git -C "$RepoDir" submodule foreach --recursive git clean -xfd -f # to delete all untracked files in the submodules
if ($lastExitCode -ne "0") { throw "'git clean' in the submodules failed with exit code $lastExitCode" } if ($lastExitCode -ne "0") { throw "'git clean' in the submodules failed with exit code $lastExitCode" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ cleaned 📂$RepoDirName repository in $Elapsed sec." "✔️ cleaned 📂$RepoDirName repo in $Elapsed sec"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Pulls Git repo updates Pulls updates into a repo
.DESCRIPTION .DESCRIPTION
This PowerShell script pulls updates into a local Git repository (including submodules). This PowerShell script pulls the latest updates into a local Git repository (including submodules).
.PARAMETER RepoDir .PARAMETER RepoDir
Specifies the file path to the local Git repository (default is working directory) Specifies the file path to the local Git repository (default is working directory)
.EXAMPLE .EXAMPLE
@ -38,7 +38,7 @@ try {
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" } if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ updated 📂$RepoDirName repository in $Elapsed sec." "✔️ updated 📂$RepoDirName repo in $Elapsed sec"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"