Updated list-commits.ps1 and watch-commits.ps1

This commit is contained in:
Markus Fleschutz 2025-01-08 14:29:32 +01:00
parent 4c19a92220
commit f1a20bc962
2 changed files with 15 additions and 15 deletions

View File

@ -4,7 +4,7 @@
.DESCRIPTION .DESCRIPTION
This PowerShell script lists all commits in a Git repository. Supported output formats are: pretty, list, compact, normal or JSON. This PowerShell script lists all commits in a Git repository. Supported output formats are: pretty, list, compact, normal or JSON.
.PARAMETER RepoDir .PARAMETER RepoDir
Specifies the path to the Git repository. Specifies the file path to the local Git repository.
.PARAMETER Format .PARAMETER Format
Specifies the output format: pretty|list|compact|normal|JSON (pretty by default) Specifies the output format: pretty|list|compact|normal|JSON (pretty by default)
.EXAMPLE .EXAMPLE
@ -20,40 +20,40 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$RepoDir = "$PWD", [string]$Format = "pretty") param([string]$pathToRepo = "$PWD", [string]$format = "pretty")
try { try {
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access directory: $pathToRepo" }
$Null = (git --version) $null = (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-Progress "Fetching latest updates..." Write-Progress "Fetching latest updates..."
& git -C "$RepoDir" fetch --all --quiet & git -C "$pathToRepo" fetch --all --quiet
if ($lastExitCode -ne "0") { throw "'git fetch' failed" } if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
Write-Progress -Completed "Done." Write-Progress -Completed "Done."
if ($Format -eq "pretty") { if ($format -eq "pretty") {
"" ""
& git -C "$RepoDir" log --graph --format=format:'%C(bold yellow)%s%C(reset)%d by %an 🕘%cs 🔗%h' --all & git -C "$pathToRepo" log --graph --format=format:'%C(bold yellow)%s%C(reset)%d by %an 🕘%cs 🔗%h' --all
} elseif ($Format -eq "list") { } elseif ($format -eq "list") {
"" ""
"Hash Date Author Description" "Hash Date Author Description"
"---- ---- ------ -----------" "---- ---- ------ -----------"
& git log --pretty=format:"%h%x09%cs%x09%an%x09%s" & git log --pretty=format:"%h%x09%cs%x09%an%x09%s"
} elseif ($Format -eq "compact") { } elseif ($format -eq "compact") {
"" ""
"List of Git Commits" "List of Git Commits"
"-------------------" "-------------------"
& git -C "$RepoDir" log --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an %cr%Creset' --abbrev-commit & git -C "$pathToRepo" log --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an %cr%Creset' --abbrev-commit
if ($lastExitCode -ne "0") { throw "'git log' failed" } if ($lastExitCode -ne "0") { throw "'git log' failed" }
} elseif ($Format -eq "JSON") { } elseif ($format -eq "JSON") {
& git -C "$RepoDir" log --pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n "subject": "%s",%n "sanitized_subject_line": "%f",%n "body": "%b",%n "commit_notes": "%N",%n "verification_flag": "%G?",%n "signer": "%GS",%n "signer_key": "%GK",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%aD"%n },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "date": "%cD"%n }%n},' & git -C "$pathToRepo" log --pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n "subject": "%s",%n "sanitized_subject_line": "%f",%n "body": "%b",%n "commit_notes": "%N",%n "verification_flag": "%G?",%n "signer": "%GS",%n "signer_key": "%GK",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%aD"%n },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "date": "%cD"%n }%n},'
} else { } else {
"" ""
"List of Git Commits" "List of Git Commits"
"-------------------" "-------------------"
& git -C "$RepoDir" log & git -C "$pathToRepo" log
if ($lastExitCode -ne "0") { throw "'git log' failed" } if ($lastExitCode -ne "0") { throw "'git log' failed" }
} }
exit 0 # success exit 0 # success

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Watch commits live. Watch Git commits live.
.DESCRIPTION .DESCRIPTION
This PowerShell script continuously lists the latest commit in a Git repository in real-time. This PowerShell script continuously lists the latest commits in a Git repository in real-time.
.PARAMETER pathToRepo .PARAMETER pathToRepo
Specifies the file path to the local Git repository. Specifies the file path to the local Git repository.
.EXAMPLE .EXAMPLE