PortValhalla/scripts/Common/Software/git/main.fish

92 lines
2.6 KiB
Fish
Raw Normal View History

2024-07-15 10:10:06 +00:00
#!/bin/env fish
begin
2024-07-15 18:24:47 +00:00
set -l dir (status dirname)
2024-07-15 10:10:06 +00:00
source "$(status dirname)/../../Scripts/software.fish"
function configureGit -S -V dir -a name
2024-07-15 18:24:47 +00:00
source "$dir/../../Scripts/config.fish"
set -l root "valhalla"
2024-07-19 23:43:53 +00:00
set -l user
2024-07-19 23:31:04 +00:00
set -l configArgs
2024-07-15 18:24:47 +00:00
2024-07-19 23:46:11 +00:00
function setConfig -S
2024-07-19 23:43:53 +00:00
sudo -u "$user" git config $configArgs $argv
2024-07-15 12:47:06 +00:00
end
2024-07-20 02:23:51 +00:00
if [ -z "$name" ]
2024-07-19 23:43:53 +00:00
set user "root"
2024-07-19 23:36:22 +00:00
set configArgs "--system"
2024-07-19 23:31:04 +00:00
else
set root "$root.users.$name"
2024-07-19 23:43:53 +00:00
set user "$name"
2024-07-19 23:36:22 +00:00
set configArgs "--global"
2024-07-19 23:31:04 +00:00
set -l displayName "$root.displayName"
set -l mailAddress "$root.mailAddress"
if isSet "$displayName"
setConfig user.name (getConfig "$displayName")
end
if isSet "$mailAddress"
setConfig user.email (getConfig "$mailAddress")
end
end
set -l branch "$root.git.defaultBranch"
2024-07-15 12:58:54 +00:00
if isSet "$branch"
setConfig init.defaultBranch (getConfig "$branch")
end
2024-07-15 10:10:06 +00:00
begin # Git Flow
set -l dir (mktemp -d)
2024-07-15 12:58:54 +00:00
begin
2024-07-19 23:59:33 +00:00
set -l key "$root.git.flow"
2024-07-15 18:24:47 +00:00
set -l mainKey "$key.mainBranch"
set -l devKey "$key.devBranch"
2024-07-20 02:17:42 +00:00
git -C "$dir" init
git -C "$dir" commit --allow-empty -m "Initial commit" > /dev/null
git -C "$dir" branch master || true &> /dev/null
git -C "$dir" branch main || true &> /dev/null
git -C "$dir" branch dev || true &> /dev/null
yes "" | git -C "$dir" flow init &> /dev/null
2024-07-15 18:24:47 +00:00
if isSet "$mainKey"
2024-07-20 02:17:42 +00:00
sudo git -C "$dir" flow config set $configArgs master (getConfig "$mainKey") > /dev/null
2024-07-15 18:24:47 +00:00
else
true
end
if isSet "$devKey"
2024-07-20 02:17:42 +00:00
sudo git -C "$dir" flow config set $configArgs develop (getConfig "$devKey") > /dev/null
2024-07-15 18:24:47 +00:00
else
true
end
2024-07-15 12:58:54 +00:00
end
2024-07-15 10:10:06 +00:00
rm -rf "$dir"
end
2024-07-15 18:24:47 +00:00
begin # Aliases
2024-07-19 23:38:53 +00:00
set -l key "$root.git.aliases"
set -l aliases (getConfig "$key" --json)
2024-07-15 18:24:47 +00:00
for name in (echo "$aliases" | jq 'keys[]' --raw-output0 | string split0)
setConfig "alias.$name" (getConfig "$key.$name")
end
end
2024-07-15 10:10:06 +00:00
end
2024-07-19 23:51:14 +00:00
function configureSW -S -V dir
configureGit
end
function userConfig -S -V dir -a name
configureGit "$name"
end
2024-07-19 23:51:14 +00:00
runInstaller $argv
2024-07-15 10:10:06 +00:00
end