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:
Tim Byrne 2017-01-26 08:29:51 -06:00
parent 76d90db627
commit d28df86494
No known key found for this signature in database
GPG Key ID: 6CBE24C2FD8CF76E
4 changed files with 105 additions and 20 deletions

View File

@ -129,3 +129,74 @@ setup() {
return 1
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
}

View File

@ -290,13 +290,13 @@ function test_alt() {
echo "
When the command 'alt' is provided
and file matches only ##SYSTEM
after setting alt.os
after setting local.os
Report the linking
Verify correct file is linked
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' ''
}
@ -304,13 +304,13 @@ function test_alt() {
echo "
When the command 'alt' is provided
and file matches only ##SYSTEM.HOST
after setting alt.host
after setting local.host
Report the linking
Verify correct file is linked
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' ''
}
@ -318,12 +318,12 @@ function test_alt() {
echo "
When the command 'alt' is provided
and file matches only ##SYSTEM.HOST.USER
after setting alt.user
after setting local.user
Report the linking
Verify correct file is linked
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' ''
}

View File

@ -74,7 +74,7 @@ function test_alt() {
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
local c_base="wild-class-$WILD_C"
@ -118,7 +118,7 @@ function test_alt() {
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
local c_base="wild-class-system-$WILD_C"
@ -170,7 +170,7 @@ function test_alt() {
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
local c_base="wild-class-system-host-$WILD_C"
@ -199,7 +199,7 @@ function test_alt() {
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
local c_base="wild-class-system-host-user-$WILD_C"

34
yadm
View File

@ -114,26 +114,26 @@ function alt() {
require_repo
match_class="$(config alt.class)"
match_class="$(config local.class)"
if [ -z "$match_class" ] ; then
match_class="()"
fi
match_class="(%|$match_class)"
match_system="$(config alt.os)"
match_system="$(config local.os)"
if [ -z "$match_system" ] ; then
match_system=$(uname -s)
fi
match_system="(%|$match_system)"
match_host="$(config alt.host)"
match_host="$(config local.host)"
if [ -z "$match_host" ] ; then
match_host=$(hostname)
match_host=${match_host%%.*} #; trim any domain from hostname
fi
match_host="(%|$match_host)"
match_user="$(config alt.user)"
match_user="$(config local.user)"
if [ -z "$match_user" ] ; then
match_user=$(id -u -n)
fi
@ -275,15 +275,21 @@ EOF
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
#; with no parameters, provide some helpful documentation
cat << EOF
yadm supports the following configurations:
alt.class
alt.host
alt.os
alt.user
local.class
local.host
local.os
local.user
yadm.auto-alt
yadm.auto-perms
yadm.git-program
@ -296,12 +302,20 @@ Please read the CONFIGURATION section in the man
page for more details about configurations, and
how to adjust them.
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
#; operate on the yadm configuration file
git config --file="$(mixed_path "$YADM_CONFIG")" "$@"
CHANGES_POSSIBLE=1
fi
}