Functions/Update-GitRemote.ps1
function Update-GitRemote { [CmdletBinding()] [OutputType([LibGit2Sharp.Remote])] param ( [string] $RepoRoot, [Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)] [string] $Name, # Pipe in PSGitHub.Repository [Parameter(ValueFromPipelineByPropertyName, DontShow)] [string] $CloneUrl, [string] $Url, # Update the remote HEAD (also known as default branch). [Alias('DefaultBranch')] [string] $Head, [string] $PushUrl, [LibGit2Sharp.TagFetchMode] $TagFetchMode ) process { $repo = Find-GitRepository -Verify if (-not $repo) { return } $outerParams = $PSBoundParameters if ($Url -or $CloneUrl -or $PushUrl -or $TagFetchMode) { $repo.Network.Remotes.Update($Name, @( { param([LibGit2Sharp.RemoteUpdater] $updater) if ($outerParams.ContainsKey('Url')) { $updater.Url = $Url } if ($outerParams.ContainsKey('CloneUrl')) { $updater.Url = $CloneUrl } if ($outerParams.ContainsKey('PushUrl')) { $updater.PushUrl = $PushUrl } if ($outerParams.ContainsKey('TagFetchMode')) { $updater.TagFetchMode = $TagFetchMode } })) } if ($Head) { $target = if ($Head.StartsWith('refs/')) { $repo.Refs[$Head] } elseif ($Head.StartsWith("$Name/")) { $repo.Refs["refs/remotes/$Head"] } else { $repo.Refs["refs/remotes/$Name/$Head"] } $repo.Refs.UpdateTarget($repo.Refs["refs/remotes/$Name/HEAD"], $target) | Out-Null } $repo.Network.Remotes[$Name] } } |