PowerShell/Scripts/list-commits.ps1

37 lines
1.1 KiB
PowerShell
Raw Normal View History

2021-03-10 11:22:47 +01:00
#!/bin/powershell
<#
2021-03-10 16:00:16 +01:00
.SYNTAX ./list-commits.ps1 [<repo-dir>] [<format>]
.DESCRIPTION lists all commits of the current/given Git repository
2021-03-10 11:22:47 +01:00
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
2021-03-10 16:00:16 +01:00
param($RepoDir = "$PWD", $Format = "compact")
2021-03-10 11:22:47 +01:00
try {
write-progress "Fetching changes in Git repository $RepoDir ..."
2021-03-10 11:22:47 +01:00
if (-not(test-path "$RepoDir")) { throw "Can't access Git repository directory: $RepoDir" }
2021-03-10 11:22:47 +01:00
set-location $RepoDir
& git --version
2021-03-10 11:22:47 +01:00
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
& git fetch --all --recurse-submodules
2021-03-10 16:00:16 +01:00
if ($lastExitCode -ne "0") { throw "'git fetch --all --recurse-submodules' failed" }
2021-03-10 11:22:47 +01:00
write-output "List of commits in Git repository $($RepoDir):"
2021-03-10 16:00:16 +01:00
if ($Format -eq "compact") {
2021-03-10 16:18:48 +01:00
& git log --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an %cr%Creset' --abbrev-commit
2021-03-10 16:00:16 +01:00
} else {
& git log
}
2021-03-10 11:22:47 +01:00
if ($lastExitCode -ne "0") { throw "'git log' failed" }
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}