mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-25 17:33:17 +01:00
Update list-branches.ps1
This commit is contained in:
parent
885abeb385
commit
7ee714e3a9
@ -2,11 +2,11 @@
|
||||
.SYNOPSIS
|
||||
Lists Git branches
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists all branches in a Git repository.
|
||||
.PARAMETER RepoDir
|
||||
This PowerShell script lists branches in a Git repository - either all (default) or by a search pattern.
|
||||
.PARAMETER pathToRepo
|
||||
Specifies the path to the Git repository (current working directory by default)
|
||||
.PARAMETER SearchPattern
|
||||
Specifies the search patter (anything by default)
|
||||
.PARAMETER searchPattern
|
||||
Specifies the search pattern ("*", anything by default)
|
||||
.EXAMPLE
|
||||
PS> ./list-branches.ps1
|
||||
|
||||
@ -19,28 +19,28 @@
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$RepoDir = "$PWD", [string]$SearchPattern = "*")
|
||||
param([string]$pathToRepo = "$PWD", [string]$searchPattern = "*")
|
||||
|
||||
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 repo folder '$pathToRepo' - maybe a typo or missing folder permissions?" }
|
||||
|
||||
$Null = (git --version)
|
||||
$null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
& git -C "$RepoDir" fetch
|
||||
& git -C "$pathToRepo" fetch
|
||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||
|
||||
$Branches = $(git -C "$RepoDir" branch --list --remotes --no-color --no-column)
|
||||
$branches = $(git -C "$pathToRepo" branch --list --remotes --no-color --no-column)
|
||||
if ($lastExitCode -ne "0") { throw "'git branch --list' failed" }
|
||||
|
||||
""
|
||||
"List of Git Branches"
|
||||
"--------------------"
|
||||
foreach($Branch in $Branches) {
|
||||
if ("$Branch" -match "origin/HEAD") { continue }
|
||||
$BranchName = $Branch.substring(9)
|
||||
if ("$BranchName" -notlike "$SearchPattern") { continue }
|
||||
"$BranchName"
|
||||
foreach($branch in $branches) {
|
||||
if ("$branch" -match "origin/HEAD") { continue }
|
||||
$branchName = $branch.substring(9)
|
||||
if ("$branchName" -notlike "$searchPattern") { continue }
|
||||
"$branchName"
|
||||
}
|
||||
""
|
||||
exit 0 # success
|
||||
|
Loading…
Reference in New Issue
Block a user