Background:
I'm trying to filter a specific GIT branch from my local branches. Therefore I'm using git branch --all.
Powershell specific question:
I'm performing pipeline filtering via Where-Object and want to ensure that only one object and not an array is returned from the pipeline.
I've e.g. :
$branch = Invoke-Expression "git branch --all" | % { $_.Trim('*').Trim() | ? { $_ -match "MySpecificBranchRegex" }
If I mess up my specific filter regex $branch might be an array and not a string.
Is there an elegant way to ensure only one string is returned. Possible solutions I don't like:
- Call
Select-Object -First 1at the end of the pipeline - Perform if '$arr.GetType().BaseType.Name -eq "Array"`
Thx.