Store class/os/host/user overrides in the local repo config
Overrides are meant to be local to each system, unlike other configurations which are often added to a user's dotfiles repository. With this change, the configurations change names: alt.class => local.class alt.os => local.os alt.host => local.host alt.user => local.user
This commit is contained in:
parent
76d90db627
commit
d28df86494
|
@ -129,3 +129,74 @@ setup() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "Command 'config' (local read)" {
|
||||||
|
echo "
|
||||||
|
When 'config' command is provided,
|
||||||
|
and an attribute is provided
|
||||||
|
and the attribute is configured
|
||||||
|
and the attribute is local.*
|
||||||
|
Fetch the value from the repo config
|
||||||
|
Report the requested value
|
||||||
|
Exit with 0
|
||||||
|
"
|
||||||
|
|
||||||
|
#; write local attributes
|
||||||
|
build_repo
|
||||||
|
for loption in class os host user; do
|
||||||
|
GIT_DIR="$T_DIR_REPO" git config "local.$loption" "custom_$loption"
|
||||||
|
done
|
||||||
|
|
||||||
|
#; run config
|
||||||
|
for loption in class os host user; do
|
||||||
|
run "${T_YADM_Y[@]}" config "local.$loption"
|
||||||
|
#; validate status and output
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
if [ "$output" != "custom_$loption" ]; then
|
||||||
|
echo "ERROR: Incorrect value returned. Expected 'custom_$loption', got '$output'"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Command 'config' (local write)" {
|
||||||
|
echo "
|
||||||
|
When 'config' command is provided,
|
||||||
|
and an attribute is provided
|
||||||
|
and a value is provided
|
||||||
|
and the attribute is local.*
|
||||||
|
Report no output
|
||||||
|
Write the value to the repo config
|
||||||
|
Exit with 0
|
||||||
|
"
|
||||||
|
|
||||||
|
build_repo
|
||||||
|
local expected
|
||||||
|
local linecount
|
||||||
|
expected="[local]\n"
|
||||||
|
linecount=1
|
||||||
|
for loption in class os host user; do
|
||||||
|
#; update expected
|
||||||
|
expected="$expected\t$loption = custom_$loption\n"
|
||||||
|
((linecount+=1))
|
||||||
|
#; write local attributes
|
||||||
|
run "${T_YADM_Y[@]}" config "local.$loption" "custom_$loption"
|
||||||
|
|
||||||
|
#; validate status and output
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ "$output" = "" ]
|
||||||
|
done
|
||||||
|
|
||||||
|
#; validate data
|
||||||
|
local config
|
||||||
|
config=$(tail "-$linecount" "$T_DIR_REPO/config")
|
||||||
|
expected=$(echo -ne "$expected")
|
||||||
|
if [ "$config" != "$expected" ]; then
|
||||||
|
echo "ERROR: Config does not match expected"
|
||||||
|
echo -e "$config"
|
||||||
|
echo -e "EXPECTED:\n$expected"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -290,13 +290,13 @@ function test_alt() {
|
||||||
echo "
|
echo "
|
||||||
When the command 'alt' is provided
|
When the command 'alt' is provided
|
||||||
and file matches only ##SYSTEM
|
and file matches only ##SYSTEM
|
||||||
after setting alt.os
|
after setting local.os
|
||||||
Report the linking
|
Report the linking
|
||||||
Verify correct file is linked
|
Verify correct file is linked
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.os custom_system
|
GIT_DIR="$T_DIR_REPO" git config local.os custom_system
|
||||||
test_alt 'override_system' 'false' ''
|
test_alt 'override_system' 'false' ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,13 +304,13 @@ function test_alt() {
|
||||||
echo "
|
echo "
|
||||||
When the command 'alt' is provided
|
When the command 'alt' is provided
|
||||||
and file matches only ##SYSTEM.HOST
|
and file matches only ##SYSTEM.HOST
|
||||||
after setting alt.host
|
after setting local.host
|
||||||
Report the linking
|
Report the linking
|
||||||
Verify correct file is linked
|
Verify correct file is linked
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.host custom_host
|
GIT_DIR="$T_DIR_REPO" git config local.host custom_host
|
||||||
test_alt 'override_host' 'false' ''
|
test_alt 'override_host' 'false' ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,12 +318,12 @@ function test_alt() {
|
||||||
echo "
|
echo "
|
||||||
When the command 'alt' is provided
|
When the command 'alt' is provided
|
||||||
and file matches only ##SYSTEM.HOST.USER
|
and file matches only ##SYSTEM.HOST.USER
|
||||||
after setting alt.user
|
after setting local.user
|
||||||
Report the linking
|
Report the linking
|
||||||
Verify correct file is linked
|
Verify correct file is linked
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.user custom_user
|
GIT_DIR="$T_DIR_REPO" git config local.user custom_user
|
||||||
test_alt 'override_user' 'false' ''
|
test_alt 'override_user' 'false' ''
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ function test_alt() {
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.class set_class
|
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
for WILD_C in 'local' 'wild'; do
|
||||||
local c_base="wild-class-$WILD_C"
|
local c_base="wild-class-$WILD_C"
|
||||||
|
@ -118,7 +118,7 @@ function test_alt() {
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.class set_class
|
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
for WILD_C in 'local' 'wild'; do
|
||||||
local c_base="wild-class-system-$WILD_C"
|
local c_base="wild-class-system-$WILD_C"
|
||||||
|
@ -170,7 +170,7 @@ function test_alt() {
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.class set_class
|
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
for WILD_C in 'local' 'wild'; do
|
||||||
local c_base="wild-class-system-host-$WILD_C"
|
local c_base="wild-class-system-host-$WILD_C"
|
||||||
|
@ -199,7 +199,7 @@ function test_alt() {
|
||||||
Exit with 0
|
Exit with 0
|
||||||
"
|
"
|
||||||
|
|
||||||
git config --file="$T_YADM_CONFIG" alt.class set_class
|
GIT_DIR="$T_DIR_REPO" git config local.class set_class
|
||||||
|
|
||||||
for WILD_C in 'local' 'wild'; do
|
for WILD_C in 'local' 'wild'; do
|
||||||
local c_base="wild-class-system-host-user-$WILD_C"
|
local c_base="wild-class-system-host-user-$WILD_C"
|
||||||
|
|
34
yadm
34
yadm
|
@ -114,26 +114,26 @@ function alt() {
|
||||||
|
|
||||||
require_repo
|
require_repo
|
||||||
|
|
||||||
match_class="$(config alt.class)"
|
match_class="$(config local.class)"
|
||||||
if [ -z "$match_class" ] ; then
|
if [ -z "$match_class" ] ; then
|
||||||
match_class="()"
|
match_class="()"
|
||||||
fi
|
fi
|
||||||
match_class="(%|$match_class)"
|
match_class="(%|$match_class)"
|
||||||
|
|
||||||
match_system="$(config alt.os)"
|
match_system="$(config local.os)"
|
||||||
if [ -z "$match_system" ] ; then
|
if [ -z "$match_system" ] ; then
|
||||||
match_system=$(uname -s)
|
match_system=$(uname -s)
|
||||||
fi
|
fi
|
||||||
match_system="(%|$match_system)"
|
match_system="(%|$match_system)"
|
||||||
|
|
||||||
match_host="$(config alt.host)"
|
match_host="$(config local.host)"
|
||||||
if [ -z "$match_host" ] ; then
|
if [ -z "$match_host" ] ; then
|
||||||
match_host=$(hostname)
|
match_host=$(hostname)
|
||||||
match_host=${match_host%%.*} #; trim any domain from hostname
|
match_host=${match_host%%.*} #; trim any domain from hostname
|
||||||
fi
|
fi
|
||||||
match_host="(%|$match_host)"
|
match_host="(%|$match_host)"
|
||||||
|
|
||||||
match_user="$(config alt.user)"
|
match_user="$(config local.user)"
|
||||||
if [ -z "$match_user" ] ; then
|
if [ -z "$match_user" ] ; then
|
||||||
match_user=$(id -u -n)
|
match_user=$(id -u -n)
|
||||||
fi
|
fi
|
||||||
|
@ -275,15 +275,21 @@ EOF
|
||||||
|
|
||||||
function config() {
|
function config() {
|
||||||
|
|
||||||
|
use_repo_config=0
|
||||||
|
local_options="^local\.(class|os|host|user)$"
|
||||||
|
for option in "$@"; do
|
||||||
|
[[ "$option" =~ $local_options ]] && use_repo_config=1
|
||||||
|
done
|
||||||
|
|
||||||
if [ -z "$*" ] ; then
|
if [ -z "$*" ] ; then
|
||||||
#; with no parameters, provide some helpful documentation
|
#; with no parameters, provide some helpful documentation
|
||||||
cat << EOF
|
cat << EOF
|
||||||
yadm supports the following configurations:
|
yadm supports the following configurations:
|
||||||
|
|
||||||
alt.class
|
local.class
|
||||||
alt.host
|
local.host
|
||||||
alt.os
|
local.os
|
||||||
alt.user
|
local.user
|
||||||
yadm.auto-alt
|
yadm.auto-alt
|
||||||
yadm.auto-perms
|
yadm.auto-perms
|
||||||
yadm.git-program
|
yadm.git-program
|
||||||
|
@ -296,12 +302,20 @@ Please read the CONFIGURATION section in the man
|
||||||
page for more details about configurations, and
|
page for more details about configurations, and
|
||||||
how to adjust them.
|
how to adjust them.
|
||||||
EOF
|
EOF
|
||||||
|
elif [ "$use_repo_config" -eq 1 ]; then
|
||||||
|
|
||||||
|
require_repo
|
||||||
|
|
||||||
|
#; operate on the yadm repo's configuration file
|
||||||
|
#; this is always local to the machine
|
||||||
|
git config --local "$@"
|
||||||
|
|
||||||
|
CHANGES_POSSIBLE=1
|
||||||
|
|
||||||
else
|
else
|
||||||
#; operate on the yadm configuration file
|
#; operate on the yadm configuration file
|
||||||
git config --file="$(mixed_path "$YADM_CONFIG")" "$@"
|
git config --file="$(mixed_path "$YADM_CONFIG")" "$@"
|
||||||
|
|
||||||
CHANGES_POSSIBLE=1
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue