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

86 lines
2.4 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"
2024-07-19 23:23:08 +00:00
function getSWName
echo "git"
end
2024-07-19 23:31:04 +00:00
function configureSW -S -V dir -a scope name
2024-07-15 18:24:47 +00:00
source "$dir/../../Scripts/config.fish"
2024-07-19 23:31:04 +00:00
set -l root
set -l configArgs
2024-07-15 18:24:47 +00:00
2024-07-15 12:47:06 +00:00
function setConfig
2024-07-19 23:31:04 +00:00
sudo git config $configArgs $argv
2024-07-15 12:47:06 +00:00
end
2024-07-19 23:31:04 +00:00
if [ -z "$scope" ] || [ "$scope" = "system" ]
2024-07-19 23:36:22 +00:00
set root "valhalla"
set configArgs "--system"
2024-07-19 23:31:04 +00:00
else
2024-07-19 23:36:22 +00:00
set root "valhalla.users.$name"
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)
pushd "$dir" > /dev/null
2024-07-15 12:58:54 +00:00
begin
2024-07-15 18:24:47 +00:00
set -l key valhalla.git.flow
set -l mainKey "$key.mainBranch"
set -l devKey "$key.devBranch"
2024-07-15 10:10:06 +00:00
git init
git commit --allow-empty -m "Initial commit" > /dev/null
git branch master || true &> /dev/null
git branch main || true &> /dev/null
git branch dev || true &> /dev/null
yes "" | git flow init &> /dev/null
2024-07-15 18:24:47 +00:00
if isSet "$mainKey"
2024-07-19 23:31:04 +00:00
sudo git 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-19 23:31:04 +00:00
sudo git 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
popd > /dev/null
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
end