Updated watch-commits.ps1

This commit is contained in:
Markus Fleschutz 2024-12-20 13:33:22 +01:00
parent 4298dd8d73
commit 88e0868a4c

View File

@ -7,7 +7,10 @@
Specifies the file path to the local Git repository.
.EXAMPLE
PS> ./watch-commits.ps1
Updated general.csv by Markus Fleschutz (HEAD -> main, origin/main, origin/HEAD)
TIME COMMIT
---- ------
11:25 Updated general.csv by Markus Fleschutz (HEAD -> main, origin/main, origin/HEAD)
...
.LINK
https://github.com/fleschutz/PowerShell
@ -15,7 +18,7 @@
Author: Markus Fleschutz | License: CC0
#>
param([string]$pathToRepo = "$PWD", [int]$updateInterval = 30, [int]$speed = 17)
param([string]$pathToRepo = "$PWD", [int]$updateInterval = 60, [int]$speed = 10)
try {
Write-Progress "Searching for Git executable..."
@ -26,9 +29,9 @@ try {
if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access directory: $pathToRepo" }
Write-Progress -completed "Done."
Write-Host ""
Write-Host "TIME COMMIT"
Write-Host "---- ------"
Write-Output ""
Write-Output "TIME COMMIT"
Write-Output "---- ------"
$prevLine = ""
$tzOffset = (Get-Timezone).BaseUtcOffset.TotalSeconds
for (;;) {
@ -36,10 +39,9 @@ try {
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
$line = (git -C "$pathToRepo" log origin --format=format:'%at %s by %an%d' --max-count=1)
if ($line -eq $prevLine) {
Start-Sleep -seconds $updateInterval
continue
}
if ($lastExitCode -ne "0") { throw "'git log origin' failed" }
if ("$line" -eq "$prevLine") { Start-Sleep -seconds $updateInterval; continue }
$unixTimestamp = [int64]$line.Substring(0,10)
$time = (Get-Date -day 1 -month 1 -year 1970 -hour 0 -minute 0 -second 0).AddSeconds($unixTimestamp)
$time = $time.AddSeconds($tzOffset)