-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitpullall.ps1
More file actions
executable file
·87 lines (69 loc) · 2.15 KB
/
gitpullall.ps1
File metadata and controls
executable file
·87 lines (69 loc) · 2.15 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Pulls all changes from all repositories in the current directory.
.DESCRIPTION
For each repository in subfolders:
- Check if it exists/enabled in Azure DevOps using the REST API
- Switch to main/master (unless it’s a wiki repo)
- Pull latest changes from remote
.PARAMETER Organization
The Azure DevOps organization name
.PARAMETER Project
The Azure DevOps project name
.PARAMETER Pat
Personal Access Token
#>
param (
[Parameter(Mandatory = $true)]
[string]$Organization,
[Parameter(Mandatory = $true)]
[string]$Project,
[Parameter(Mandatory = $true)]
[string]$Pat
)
# Function to call Azure DevOps API
function Test-RepoEnabled {
param (
[string]$Org,
[string]$Proj,
[string]$RepoName,
[string]$Token
)
$encodedProj = [System.Net.WebUtility]::UrlEncode($Proj)
$url = "https://dev.azure.com/$Org/$encodedProj/_apis/git/repositories/${RepoName}?api-version=7.1-preview.1"
$headers = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$Token"))
Accept = "application/json"
}
try {
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get -ErrorAction Stop
return $true
}
catch {
return $false
}
}
# Iterate over all subdirectories
Get-ChildItem -Directory | ForEach-Object {
$repoDir = $_.FullName
$repoName = $_.Name
# Check if repo exists/is enabled
if (-not (Test-RepoEnabled -Org $Organization -Proj $Project -RepoName $repoName -Token $Pat)) {
Write-Host "Repository $repoName is disabled or does not exist, skipping it."
return
}
Write-Host "Processing $repoName..."
# Configure git
git -C $repoDir config pull.rebase false | Out-Null
# Skip .wiki repos for branch switching
if ($repoName -notlike "*.wiki") {
git -C $repoDir checkout main 2>$null
if ($LASTEXITCODE -ne 0) {
git -C $repoDir checkout master 2>$null
}
}
# Fetch and pull from remote (origin)
git -C $repoDir fetch --prune
git -C $repoDir pull
}