PowerShell/Scripts/list-commits.ps1

44 lines
1.2 KiB
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
list-commits.ps1 [<repo-dir>] [<format>]
.DESCRIPTION
Lists all commits in the current/given Git repository
.EXAMPLE
PS> .\list-commits.ps1
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2021-08-03 15:53:57 +02:00
Author: Markus Fleschutz
License: CC0
2021-03-10 11:22:47 +01:00
#>
2021-07-15 15:51:22 +02:00
param([string]$RepoDir = "$PWD", [string]$Format = "compact")
2021-03-10 11:22:47 +01:00
try {
2021-03-16 08:45:53 +01:00
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir"
2021-03-10 11:22:47 +01:00
2021-04-17 11:29:32 +02:00
$Null = (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" }
2021-05-06 17:10:00 +02:00
& git fetch
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
2021-03-10 11:22:47 +01:00
write-output ""
write-output "List of Git Commits"
write-output "-------------------"
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
if ($lastExitCode -ne "0") { throw "'git log' failed" }
2021-03-10 16:00:16 +01:00
} else {
& git log
if ($lastExitCode -ne "0") { throw "'git log' failed" }
2021-03-10 16:00:16 +01:00
}
write-output ""
2021-03-15 13:51:55 +01:00
write-output ""
2021-03-10 11:22:47 +01:00
exit 0
} catch {
2021-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-03-10 11:22:47 +01:00
exit 1
}