mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-29 16:16:47 +01:00
Updated check-repo.ps1
This commit is contained in:
parent
81a8082017
commit
233864eef0
@ -1,17 +1,17 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks a repo
|
Checks a Git repository
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script verifies the integrity of a local Git repository.
|
This PowerShell script verifies the integrity of a local Git repository.
|
||||||
.PARAMETER RepoDir
|
.PARAMETER pathToRepo
|
||||||
Specifies the path to the 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
|
||||||
⏳ (1/10) Searching for Git executable... git version 2.41.0.windows.3
|
⏳ (1/10) Searching for Git executable... git version 2.41.0.windows.3
|
||||||
⏳ (2/10) Checking local folder... 📂C:\MyRepo
|
⏳ (2/10) Checking local repository... 📂C:\MyRepo
|
||||||
⏳ (3/10) Querying remote URL... git@github.com:fleschutz/PowerShell.git
|
⏳ (3/10) Querying remote URL... git@github.com:fleschutz/PowerShell.git
|
||||||
⏳ (4/10) Querying current branch... main
|
⏳ (4/10) Querying current branch... main
|
||||||
⏳ (5/10) Fetching remote updates...
|
⏳ (5/10) Fetching remote updates... OK
|
||||||
⏳ (6/10) Querying latest tag... v0.8 (commit 02171a401d83b01a0cda0af426840b605e617f08)
|
⏳ (6/10) Querying latest tag... v0.8 (commit 02171a401d83b01a0cda0af426840b605e617f08)
|
||||||
⏳ (7/10) Verifying data integrity...
|
⏳ (7/10) Verifying data integrity...
|
||||||
...
|
...
|
||||||
@ -21,17 +21,17 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$RepoDir = "$PWD")
|
param([string]$pathToRepo = "$PWD")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
Write-Host "⏳ (1/10) Searching for Git executable... " -noNewline
|
Write-Host "⏳ (1/10) Searching for Git executable... " -noNewline
|
||||||
& git --version
|
& git --version
|
||||||
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 folder... " -noNewline
|
Write-Host "⏳ (2/10) Checking local repository... " -noNewline
|
||||||
$FullPath = Resolve-Path "$RepoDir"
|
$FullPath = Resolve-Path "$pathToRepo"
|
||||||
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"
|
||||||
|
|
||||||
@ -43,14 +43,15 @@ try {
|
|||||||
& git -C "$FullPath" branch --show-current
|
& git -C "$FullPath" branch --show-current
|
||||||
if ($lastExitCode -ne "0") { throw "'git branch --show-current' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git branch --show-current' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
Write-Host "⏳ (5/10) Fetching remote updates..."
|
Write-Host "⏳ (5/10) Fetching remote updates... " -noNewline
|
||||||
& git -C "$FullPath" fetch
|
& git -C "$FullPath" fetch --all --recurse-submodules --tags --force --quiet
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }
|
||||||
|
Write-Host "OK"
|
||||||
|
|
||||||
Write-Host "⏳ (6/10) Querying latest tag... " -noNewline
|
Write-Host "⏳ (6/10) Querying latest tag... " -noNewline
|
||||||
$LatestTagCommitID = (git -C "$FullPath" rev-list --tags --max-count=1)
|
$latestTagCommitID = (git -C "$FullPath" rev-list --tags --max-count=1)
|
||||||
$LatestTagName = (git -C "$FullPath" describe --tags $LatestTagCommitID)
|
$latestTagName = (git -C "$FullPath" describe --tags $latestTagCommitID)
|
||||||
Write-Host "$LatestTagName (commit $LatestTagCommitID)"
|
Write-Host "$latestTagName (commit $latestTagCommitID)"
|
||||||
|
|
||||||
Write-Host "⏳ (7/10) Verifying data integrity..."
|
Write-Host "⏳ (7/10) Verifying data integrity..."
|
||||||
& git -C "$FullPath" fsck
|
& git -C "$FullPath" fsck
|
||||||
@ -68,9 +69,9 @@ try {
|
|||||||
& git -C "$FullPath" status
|
& git -C "$FullPath" status
|
||||||
if ($lastExitCode -ne "0") { throw "'git status --short' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git status --short' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
$RepoDirName = (Get-Item "$FullPath").Name
|
$repoDirName = (Get-Item "$FullPath").Name
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"✔️ Checked repo 📂$RepoDirName in $Elapsed sec"
|
"✔️ Checked 📂$repoDirName repository 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])"
|
||||||
|
Loading…
Reference in New Issue
Block a user