-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-install.ps1
92 lines (51 loc) · 1.92 KB
/
git-install.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
84
85
86
87
88
89
90
91
92
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# Check if Git is installed
function IsGitInstalled {
Write-Host "Checking if Git is installed..."
$gitInstalled = Get-Command git -ErrorAction SilentlyContinue
return $null -ne $gitInstalled
}
# Get the installed Git version
function GetGitVersion {
Write-Host "Getting installed Git version..."
$gitVersion = git --version
return $gitVersion
}
# Install Git using winget
function InstallGit {
Write-Host "Installing Git using winget..."
winget install -e --id Git.Git --accept-package-agreements --accept-source-agreements --silent
# Refresh the PATH variable in the current session (in order for the 'git' command to work)
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User")
}
function UpdateAvailable {
Write-Host "Checking if update available..."
return $(winget upgrade | Select-String -Pattern "Git.Git")
}
# Update Git using winget
function UpdateGit {
Write-Host "Updating Git using winget..."
winget upgrade -n Git.Git
}
# Check if Git is already installed
if (IsGitInstalled) {
Write-Host "Git is already installed."
$installedVersion = GetGitVersion
Write-Host "Installed Git version: $installedVersion"
$updateAvailable = UpdateAvailable
# Check if the "updateNewer" parameter is set to update Git to a newer version
if ($updateNewer -and $updateAvailable) {
UpdateGit
$installedVersion = GetGitVersion
Write-Host "Git updated to the latest version: $installedVersion"
}
} else {
InstallGit
$installedVersion = GetGitVersion
Write-Host "Git installed successfully. Version: $installedVersion"
}
# Output the installed Git version
$installedVersion
git clone https://github.com/norsemangrey/.dotfiles.git
Set-Location ./.dotfiles
. ./install.ps1