Updated check-repo.ps1

This commit is contained in:
Markus Fleschutz
2025-07-04 10:05:56 +02:00
parent e69f06b3ad
commit 8a4eb1b42b

View File

@ -1,9 +1,9 @@
<# <#
.SYNOPSIS .SYNOPSIS
Checks a Git repository Checks a Git repo
.DESCRIPTION .DESCRIPTION
This PowerShell script verifies the integrity of a local Git repository and performs maintenance tasks. This PowerShell script verifies the integrity of a local Git repository and performs maintenance tasks.
.PARAMETER pathToRepo .PARAMETER path
Specifies the file path to the local Git repository (current working directory by default) Specifies the file path to the local Git repository (current working directory by default)
.EXAMPLE .EXAMPLE
PS> ./check-repo.ps1 C:\MyRepo PS> ./check-repo.ps1 C:\MyRepo
@ -21,7 +21,7 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$pathToRepo = "$PWD") param([string]$path = "$PWD")
try { try {
$stopWatch = [system.diagnostics.stopwatch]::startNew() $stopWatch = [system.diagnostics.stopwatch]::startNew()
@ -31,7 +31,7 @@ try {
if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" } if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" }
Write-Host "⏳ (2/10) Checking local repository... " -noNewline Write-Host "⏳ (2/10) Checking local repository... " -noNewline
$FullPath = Resolve-Path "$pathToRepo" $FullPath = Resolve-Path "$path"
if (!(Test-Path "$FullPath" -pathType Container)) { throw "Can't access folder: $FullPath" } if (!(Test-Path "$FullPath" -pathType Container)) { throw "Can't access folder: $FullPath" }
"$FullPath" "$FullPath"
@ -71,7 +71,7 @@ try {
$repoDirName = (Get-Item "$FullPath").Name $repoDirName = (Get-Item "$FullPath").Name
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds [int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"Checked 📂$repoDirName repo in $($elapsed)s." "Repo '$repoDirName' has been checked in $($elapsed)s."
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)" "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)"