Skip to content

Commit

Permalink
Improve XDG_CONFIG_HOME tests and document the new behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas committed Aug 11, 2016
1 parent 1cebb29 commit fc35ecc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
9 changes: 8 additions & 1 deletion doc/tig.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,15 @@ TIG_NO_DISPLAY::

FILES
-----
'$XDG_CONFIG_HOME/tig/config::
'~/.config/tig/config'::
'~/.tigrc'::
User configuration file. See manpage:tigrc[5] for examples.
The Tig user configuration file is loaded in the following way. If
`$XDG_CONFIG_HOME` is set, read user configuration from
`$XDG_CONFIG_HOME/tig/config`. If `$XDG_CONFIG_HOME` is empty or
undefined, read user configuration from `~/.config/tig/config` if it
exists and fall back to `~/.tigrc` if it does not exist. See
manpage:tigrc[5] for examples.
'{sysconfdir}/tigrc'::
System wide configuration file.
Expand Down
51 changes: 27 additions & 24 deletions test/tigrc/xdg-config-home-test
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@

. libtest.sh

tigrc <<EOF
This tigrc file should not be loaded!
EOF

steps "
<Ctrl-t>
"

#export TIGRC_SYSTEM="should-not-be-loaded"
export XDG_CONFIG_HOME="$HOME/.config"
mkdir -p "$XDG_CONFIG_HOME/tig"

cat > "$XDG_CONFIG_HOME/tig/config" <<EOF
bind generic <Ctrl-t> @sh -c 'echo ran > ~/RUNME'
EOF

test_tig status

assert_equals stderr <<EOF
EOF

assert_equals RUNME <<EOF
ran
EOF
mkdir -p "$HOME/etc/tig" "$HOME/.config/tig"

check()
{
name="$(echo "$1" | tr / -)"
path="$HOME/$1"
env="${2:-undefined}"

case "$env" in
undefined) unset XDG_CONFIG_HOME ;;
*) export "$env" ;;
esac

mkdir -p "$(dirname "$path")"
tig_script "case-$name" '<Ctrl-t>'
echo "bind generic <Ctrl-t> @sh -c 'echo $name >> $HOME/$TEST_NAME.out'" > "$path"
test_tig status
assert_equals "$TEST_NAME.out" "$name"
assert_equals "$TEST_NAME.stderr" ''
}

unset XDG_CONFIG_HOME

check .tigrc
check .config/tig/config
check .config/tig/config XDG_CONFIG_HOME="$HOME"
check etc/tig/config XDG_CONFIG_HOME="$HOME/etc"

0 comments on commit fc35ecc

Please sign in to comment.