This repository was archived by the owner on Sep 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathUpdateSubmodule.ps1
More file actions
68 lines (51 loc) · 1.53 KB
/
Copy pathUpdateSubmodule.ps1
File metadata and controls
68 lines (51 loc) · 1.53 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<#
.SYNOPSIS
Updates Git submodules in the local workspace.
.DESCRIPTION
Authentication must be configured before running this script. Use Git
Credential Manager, another Git credential helper, or an SSH agent.
This script intentionally does not accept credentials or embed them in
submodule URLs, Git configuration, command-line arguments, or log output.
#>
[CmdletBinding()]
param(
[switch] $Remote
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$workingFolder = $PSScriptRoot
$submoduleMetaFile = Join-Path -Path $workingFolder -ChildPath '.gitmodules'
function Invoke-Git {
param(
[Parameter(Mandatory)]
[string[]] $GitArguments
)
Write-Host ('git {0}' -f ($GitArguments -join ' '))
& git -C $workingFolder @GitArguments
if ($LASTEXITCODE -ne 0) {
throw "Git exited with code $LASTEXITCODE."
}
}
Get-Command git -ErrorAction Stop | Out-Null
if (-not (Test-Path -LiteralPath $submoduleMetaFile -PathType Leaf)) {
throw "The submodule metadata file '$submoduleMetaFile' does not exist."
}
Write-Host '************************************************'
# Synchronize local submodule configuration with .gitmodules without
# rewriting URLs or embedding credentials.
Invoke-Git -GitArguments @(
'submodule'
'sync'
'--recursive'
)
$updateArguments = @(
'submodule'
'update'
'--init'
'--recursive'
)
if ($Remote) {
$updateArguments += '--remote'
}
Invoke-Git -GitArguments $updateArguments
Write-Host '************************************************'