From 9d4b5a7b185e6b64553e5ed57fa518315deaf08a Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 10 Mar 2021 11:22:47 +0100 Subject: [PATCH] Added list-commits.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/list-commits.ps1 | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100755 Scripts/list-commits.ps1 diff --git a/Data/scripts.csv b/Data/scripts.csv index 96f560b4..c22f4cda 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -41,6 +41,7 @@ list-aliases.ps1, lists all PowerShell aliases list-anagrams.ps1, lists all anagrams of the given word list-automatic-variables.ps1, lists the automatic variables of PowerShell list-branches.ps1, lists the branches of the current/given Git repository +list-commits.ps1, lists the commits of the current/given Git repository in the given branch list-current-timezone.ps1, lists the current time zone details list-clipboard.ps1, lists the contents of the clipboard list-environment-variables.ps1, lists all environment variables diff --git a/README.md b/README.md index ed06af7b..3e132794 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ Collection of PowerShell Scripts * [fetch-repo.ps1](Scripts/fetch-repo.ps1) - fetches a single Git repository at the current/given directory (including submodules) * [fetch-repos.ps1](Scripts/fetch-repos.ps1) - fetches all Git repositories under the current/given directory (including submodules) * [list-branches.ps1](Scripts/list-branches.ps1) - lists the branches of the current/given Git repository +* [list-commits.ps1](Scripts/list-commits.ps1) - lists the commits of the current/given Git repository in the given branch * [switch-branch.ps1](Scripts/switch-branch.ps1) - switches the current Git repository to the given branch (including submodules) * [update-repos.ps1](Scripts/update-repos.ps1) - updates all Git repositories under the current/given directory (including submodules) diff --git a/Scripts/list-commits.ps1 b/Scripts/list-commits.ps1 new file mode 100755 index 00000000..6ca013c5 --- /dev/null +++ b/Scripts/list-commits.ps1 @@ -0,0 +1,36 @@ +#!/bin/powershell +<# +.SYNTAX ./list-commits.ps1 [] [] +.DESCRIPTION lists all commits of the current/given Git repository in the given branch +.LINK https://github.com/fleschutz/PowerShell +.NOTES Author: Markus Fleschutz / License: CC0 +#> + +param($RepoDir = "$PWD", $Branch = "main") + +try { + write-output "Listing commits of Git repository $RepoDir ..." + + if (-not(test-path "$RepoDir")) { throw "Can't access Git repository at: $RepoDir" } + set-location $RepoDir + + $null = (git --version) + if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } + + & git switch --recurse-submodules $Branch + if ($lastExitCode -ne "0") { throw "'git switch --recurse-submodules $Branch' failed" } + + & git submodule update --init --recursive + if ($lastExitCode -ne "0") { throw "'git submodule update' failed" } + + & git pull --recurse-submodules + if ($lastExitCode -ne "0") { throw "'git pull' failed" } + + & git log + if ($lastExitCode -ne "0") { throw "'git log' failed" } + + exit 0 +} catch { + write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}