mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-24 10:58:16 +02:00
Improve list-commits.ps1
This commit is contained in:
parent
57310cadb4
commit
6b5d9e4a98
@ -2,7 +2,7 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
list-commits.ps1 [<RepoDir>] [<Format>]
|
list-commits.ps1 [<RepoDir>] [<Format>]
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Lists all commits in a Git repository (format is: compact|normal|JSON).
|
Lists all commits in a Git repository (format is: list|compact|normal|JSON).
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> .\list-commits.ps1
|
PS> .\list-commits.ps1
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -11,7 +11,7 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$RepoDir = "$PWD", [string]$Format = "compact")
|
param([string]$RepoDir = "$PWD", [string]$Format = "list")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||||
@ -23,13 +23,17 @@ try {
|
|||||||
& git -C "$RepoDir" fetch --all --quiet
|
& git -C "$RepoDir" fetch --all --quiet
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||||
|
|
||||||
if ($Format -eq "compact") {
|
if ($Format -eq "list") {
|
||||||
|
""
|
||||||
|
"ID Date Committer Description"
|
||||||
|
"-- ---- --------- -----------"
|
||||||
|
& git log --pretty=format:"%h%x09%ad%x09%an%x09%s"
|
||||||
|
} 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 "$RepoDir" 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 "$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},'
|
||||||
} else {
|
} else {
|
||||||
@ -38,7 +42,6 @@ try {
|
|||||||
"-------------------"
|
"-------------------"
|
||||||
& git -C "$RepoDir" log
|
& git -C "$RepoDir" log
|
||||||
if ($lastExitCode -ne "0") { throw "'git log' failed" }
|
if ($lastExitCode -ne "0") { throw "'git log' failed" }
|
||||||
""
|
|
||||||
}
|
}
|
||||||
exit 0
|
exit 0
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user