Update win_git to update remote URL if different
This commit is contained in:
parent
5f9de82ca3
commit
567ed28def
@ -108,6 +108,16 @@ function Get-GitCurrentSha {
|
|||||||
return $result.stdout.Trim()
|
return $result.stdout.Trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-GitRemoteUrl {
|
||||||
|
[CmdletBinding()]
|
||||||
|
Param (
|
||||||
|
[Parameter(Mandatory = $true)] [String] $dest,
|
||||||
|
[Parameter(Mandatory = $true)] [String] $remote
|
||||||
|
)
|
||||||
|
$result = Run-Command -command "`"$git`" remote get-url $remote" -working_directory $dest
|
||||||
|
return $result.stdout.Trim()
|
||||||
|
}
|
||||||
|
|
||||||
function Invoke-GitClone {
|
function Invoke-GitClone {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
Param (
|
Param (
|
||||||
@ -187,6 +197,19 @@ function Invoke-GitSubmoduleUpdate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Invoke-GitRemoteSetUrl {
|
||||||
|
[CmdletBinding()]
|
||||||
|
Param (
|
||||||
|
[Parameter(Mandatory = $true)] [String] $dest,
|
||||||
|
[Parameter(Mandatory = $true)] [String] $remote,
|
||||||
|
[Parameter(Mandatory = $true)] [String] $url
|
||||||
|
)
|
||||||
|
$result = Run-Command -command "`"$git`" remote set-url $remote `"$url`"" -working_directory $dest
|
||||||
|
if ($result.rc -ne 0) {
|
||||||
|
$module.FailJson("Failed to set remote URL:`n" + $result.stderr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# ================================ Start logic =================================
|
# ================================ Start logic =================================
|
||||||
|
|
||||||
if (!$dest) {
|
if (!$dest) {
|
||||||
@ -207,6 +230,10 @@ if (($dest -and ![System.IO.File]::Exists($gitconfig))) {
|
|||||||
if (Test-GitLocalChanges $dest) {
|
if (Test-GitLocalChanges $dest) {
|
||||||
$module.FailJson('Local modifications exist in repository.')
|
$module.FailJson('Local modifications exist in repository.')
|
||||||
}
|
}
|
||||||
|
$url = Get-GitRemoteUrl $dest $remote
|
||||||
|
if ($url -ne $repo) {
|
||||||
|
Invoke-GitRemoteSetUrl $dest $remote $repo
|
||||||
|
}
|
||||||
Invoke-GitFetch $dest $remote $version
|
Invoke-GitFetch $dest $remote $version
|
||||||
Invoke-GitCheckout $dest $remote $version
|
Invoke-GitCheckout $dest $remote $version
|
||||||
Invoke-GitPull $dest $remote $version
|
Invoke-GitPull $dest $remote $version
|
||||||
|
Loading…
x
Reference in New Issue
Block a user