Functions/Get-GitRemote.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function Get-GitRemote {
    [CmdletBinding()]
    [OutputType([LibGit2Sharp.Remote])]
    param (
        [string] $RepoRoot,

        [Parameter(Position = 0)]
        [string] $Name
    )

    process {
        $repo = Find-GitRepository -Verify
        if (-not $repo) {
            return
        }
        if ($Name -and -not [WildcardPattern]::ContainsWildcardCharacters($Name)) {
            $repo.Network.Remotes[$Name]
        } else {
            $repo.Network.Remotes | Where-Object {
                -not $Name -or $_.Name -like $Name
            }
        }
    }
}