-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-tool-config.ps1
executable file
·54 lines (46 loc) · 1.59 KB
/
git-tool-config.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
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
#!/usr/bin/env pwsh
Param(
[Parameter()][String] $remote,
[Parameter()][String] $upstreamBranch,
[Parameter()][String] $defaultServiceLine,
[Switch] $enableAtomicPush,
[Switch] $disableAtomicPush
)
Import-Module -Scope Local "$PSScriptRoot/utils/query-state.psm1"
$oldConfig = Get-Configuration
if ($remote -ne '') {
if ((git remote) -notcontains $remote) {
throw "$remote not a valid remote for the repo."
} else {
git config scaled-git.remote $remote
}
Write-Host "Set remote: $remote"
} else {
$remote = $oldConfig.remote
Write-Host "Using previous remote: $remote"
}
if ($upstreamBranch -ne '') {
git config scaled-git.upstreamBranch $upstreamBranch
Write-Host "Set upstream: $upstreamBranch"
} else {
Write-Host "Using previous upstream: $($oldConfig.upstreamBranch)"
}
if ($defaultServiceLine -ne '') {
$expected = $remote -eq $nil ? $defaultServiceLine : "$remote/$defaultServiceLine"
$branches = $remote -eq $nil ? (git branch --format '%(refname:short)') : (git branch -r --format '%(refname:short)')
if ($branches -notcontains $expected) {
throw "$expected is not found"
}
git config scaled-git.defaultServiceLine $defaultServiceLine
Write-Host "Set default service line: $defaultServiceLine"
} else {
Write-Host "Using previous default service line: $($oldConfig.defaultServiceLine)"
}
if ($enableAtomicPush) {
git config scaled-git.atomicPushEnabled true
Write-Host "Enabling atomic push"
}
if ($disableAtomicPush) {
git config scaled-git.atomicPushEnabled false
Write-Host "Disabling atomic push"
}