PortValhalla/scripts/Common/Software/git/Main.ps1

107 lines
2.9 KiB
PowerShell
Raw Normal View History

2024-08-10 13:28:10 +00:00
. "$PSScriptRoot/../../Scripts/Software.ps1";
2024-08-22 23:43:26 +00:00
. "$PSScriptRoot/../../Scripts/System.ps1";
2024-08-10 13:28:10 +00:00
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
& {
2024-08-22 23:43:26 +00:00
$configure = {
param(
[string] $User
)
2024-09-22 15:50:05 +00:00
$getConfig = $null;
2024-08-22 23:43:26 +00:00
if ($User) {
2024-09-22 15:50:05 +00:00
$getConfig = { Get-UserConfig -UserName $User @args };
2024-08-22 23:43:26 +00:00
$sudoArgs = @("-u", $User);
$configArgs = @("--global");
2024-10-06 19:25:34 +00:00
}
else {
2024-09-22 15:50:05 +00:00
$getConfig = { Get-OSConfig @args };
2024-08-22 23:43:26 +00:00
$sudoArgs = @();
$configArgs = @("--system");
}
2024-09-22 15:50:05 +00:00
$config = & $getConfig "git";
2024-08-22 23:43:26 +00:00
<#
.SYNOPSIS
Sets a configuration option in git.
#>
function Set-GitConfig {
sudo @sudoArgs git config @configArgs @args;
}
if ((-not $IsWindows) -or $User) {
2024-09-08 15:41:30 +00:00
$branch = $config.defaultBranch;
2024-08-22 23:43:26 +00:00
if ($branch) {
Set-GitConfig "init.defaultBranch" $branch;
}
}
2024-08-23 00:01:16 +00:00
if ($User) {
$displayName = & $getConfig "displayName";
$mailAddress = & $getConfig "mailAddress";
if ($displayName) {
Set-GitConfig "user.name" $displayName;
}
if ($mailAddress) {
Set-GitConfig "user.email" $mailAddress;
}
}
2024-08-22 23:43:26 +00:00
# Git Flow
. {
$dir = New-TemporaryDirectory;
$key = "flow";
2024-09-08 15:41:30 +00:00
$mainBranch = $config."$key".mainBranch;
$devBranch = $config."$key".devBranch;
2024-08-22 23:43:26 +00:00
& {
git -C "$dir" init;
git -C "$dir" config user.name "PortValhalla";
git -C "$dir" config user.email "no-reply@valhal.la";
git -C "$dir" commit --allow-empty -m "Initial commit";
git -C "$dir" branch master;
git -C "$dir" branch dev;
git -C "$dir" flow init --defaults;
} | Out-Null;
if ($mainBranch) {
2024-10-06 19:25:34 +00:00
git -C "$dir" branch $mainBranch | Out-Null;
2024-08-22 23:43:26 +00:00
sudo @sudoArgs git -C "$dir" flow config set @configArgs master $mainBranch;
}
if ($devBranch) {
git -C "$dir" branch $devBranch | Out-Null;
sudo @sudoArgs git -C "$dir" flow config set @configArgs develop $devBranch;
}
Remove-Item -Recurse -Force $dir;
};
# Aliases
2024-09-08 15:41:30 +00:00
[PSCustomObject] $aliases = $config.aliases;
2024-08-22 23:43:26 +00:00
2024-08-22 23:52:25 +00:00
if ($aliases) {
foreach ($alias in ($aliases | Get-Member -MemberType Properties)) {
Set-GitConfig "alias.$($alias.Name)" $aliases.$($alias.Name);
}
2024-08-22 23:43:26 +00:00
}
2024-08-10 13:28:10 +00:00
};
2024-08-22 23:43:26 +00:00
2024-09-30 03:00:20 +00:00
Start-SoftwareInstaller @args `
2024-08-22 23:43:26 +00:00
-Configurator {
2024-09-30 03:00:20 +00:00
& $configure @args;
2024-08-22 23:43:26 +00:00
} `
-UserConfigurator {
param(
[hashtable] $Arguments
)
& $configure -User $Arguments.Name;
};
2024-09-30 03:00:20 +00:00
} @args;