-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathInstall-Git.ps1
More file actions
66 lines (54 loc) · 2.17 KB
/
Install-Git.ps1
File metadata and controls
66 lines (54 loc) · 2.17 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
################################################################################
## File: Install-Git.ps1
## Desc: Install Git for Windows
## Supply chain security: Git - checksum validation, Hub CLI - managed by package manager
################################################################################
if (Test-IsArm64) {
$expectedArch = "arm64"
} else {
$expectedArch = "64-bit"
}
# Install the latest version of Git for Windows
$downloadUrl = Resolve-GithubReleaseAssetUrl `
-Repo "git-for-windows/git" `
-Version "latest" `
-UrlMatchPattern "Git-*-$expectedArch.exe"
$externalHash = Get-ChecksumFromGithubRelease `
-Repo "git-for-windows/git" `
-Version "latest" `
-FileName (Split-Path $downloadUrl -Leaf) `
-HashType "SHA256"
Install-Binary `
-Url $downloadUrl `
-InstallArgs @(`
"/VERYSILENT", `
"/NORESTART", `
"/NOCANCEL", `
"/SP-", `
"/CLOSEAPPLICATIONS", `
"/RESTARTAPPLICATIONS", `
"/o:PathOption=CmdTools", `
"/o:BashTerminalOption=ConHost", `
"/o:EnableSymlinks=Enabled", `
"/COMPONENTS=gitlfs") `
-ExpectedSHA256Sum $externalHash
Update-Environment
git config --system --add safe.directory "*"
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to configure safe.directory for Git with exit code $LASTEXITCODE"
}
# Disable GCM machine-wide
[Environment]::SetEnvironmentVariable("GCM_INTERACTIVE", "Never", "Machine")
# Add to PATH
Add-MachinePathItem "C:\Program Files\Git\bin"
# Add well-known SSH host keys to ssh_known_hosts
# Write content to the file used by OpenSSH and the version includes with Git
# for Windows
$windowsSSHKnownHosts = "C:\ProgramData\ssh\ssh_known_hosts"
$gitSSHKnownHosts = "C:\Program Files\Git\etc\ssh\ssh_known_hosts"
$sshKeyScan = "C:\Program Files\Git\usr\bin\ssh-keyscan"
$githubHostKeys = &$sshKeyScan -t rsa,ecdsa,ed25519 github.com
$azureHostKeys = &$sshKeyscan -t rsa ssh.dev.azure.com
Set-Content -Encoding ASCII -Path $windowsSSHKnownHosts, $gitSSHKnownHosts -Value $githubHostKeys
Add-Content -Encoding ASCII -Path $windowsSSHKnownHosts, $gitSSHKnownHosts -Value $azureHostKeys
Invoke-PesterTests -TestFile "Git"