-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateRemotes.ps1
83 lines (63 loc) · 1.6 KB
/
updateRemotes.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$oldHost = "{{old_host_url}}"
$newHost = "{{new_host_url}}"
$gitDir = $PWD
$prefix = (Convert-Path $PWD)
$prefixSplit = $prefix.Split("\").Length
function UpdateRemote {
param([string]$repoDir)
# don't traverse these paths
if($repoDir -like "*_deps*"){
return
}
if($repoDir -like "*build*"){
return
}
# regex replace hostnames
$o = git remote get-url origin
$n = $o -replace "$oldHost", "$newHost"
if($o -ne $n){
$splitRepo = (Convert-Path $repoDir).Split("\")
$postPath = ($splitRepo | Select-Object -Skip $prefixSplit | Join-Path -ChildPath "")
$postPath = $postPath -replace "\\", "/"
git remote set-url origin $n
Write-Host "Updating /$postPath remote to $n"
}
}
function RecurseDirs {
param([string]$dirPath)
# don't traverse these paths
if($dirPath -like "*_deps*"){
return;
}
if($repoDir -like "*build*"){
return
}
# recurse through the directory structure
Get-ChildItem -Path $dirPath -Directory -Recurse -Exclude $excludedDirs | ForEach-Object {
$subDir = $_.FullName
# update current location
Set-Location $subDir
# don't traverse these paths
if($subDir -like "*_deps*"){
return
}
if($subDir -like "*build*"){
return
}
$spinnerChar = $spinner[$spinCounter/5 % $spinner.Length]
Write-Host -NoNewLine "`b"
Write-Host -NoNewLine $spinnerChar
$spinCounter++
# check if inside a git repo
if(Test-Path -Path "$subDir\.git" -PathType Container){
UpdateRemote -repoDir $subDir
return
}
}
}
$spinner = "-\|/"
$spinCounter = 0
$scriptDir = $PWD
Set-Location $gitDir
RecurseDirs -dirPath $gitDir
Set-Location $scriptDir