config --get --path: check for unset $HOME
If $HOME is unset (as in some automated build situations), currently git config --path path.home "~" git config --path --get path.home segfaults. Error out with Failed to expand user dir in: '~/' instead. Reported-by: Julien Cristau <jcristau@debian.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
28bf4ba014
commit
79bf149061
2
path.c
2
path.c
|
@ -316,6 +316,8 @@ char *expand_user_path(const char *path)
|
||||||
size_t username_len = first_slash - username;
|
size_t username_len = first_slash - username;
|
||||||
if (username_len == 0) {
|
if (username_len == 0) {
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
if (!home)
|
||||||
|
goto return_null;
|
||||||
strbuf_add(&user_path, home, strlen(home));
|
strbuf_add(&user_path, home, strlen(home));
|
||||||
} else {
|
} else {
|
||||||
struct passwd *pw = getpw_str(username, username_len);
|
struct passwd *pw = getpw_str(username, username_len);
|
||||||
|
|
|
@ -707,19 +707,41 @@ test_expect_success 'set --path' '
|
||||||
git config --path path.trailingtilde "foo~" &&
|
git config --path path.trailingtilde "foo~" &&
|
||||||
test_cmp expect .git/config'
|
test_cmp expect .git/config'
|
||||||
|
|
||||||
|
if test "${HOME+set}"
|
||||||
|
then
|
||||||
|
test_set_prereq HOMEVAR
|
||||||
|
fi
|
||||||
|
|
||||||
cat >expect <<EOF
|
cat >expect <<EOF
|
||||||
$HOME/
|
$HOME/
|
||||||
/dev/null
|
/dev/null
|
||||||
foo~
|
foo~
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'get --path' '
|
test_expect_success HOMEVAR 'get --path' '
|
||||||
git config --get --path path.home > result &&
|
git config --get --path path.home > result &&
|
||||||
git config --get --path path.normal >> result &&
|
git config --get --path path.normal >> result &&
|
||||||
git config --get --path path.trailingtilde >> result &&
|
git config --get --path path.trailingtilde >> result &&
|
||||||
test_cmp expect result
|
test_cmp expect result
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat >expect <<\EOF
|
||||||
|
/dev/null
|
||||||
|
foo~
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'get --path copes with unset $HOME' '
|
||||||
|
(
|
||||||
|
unset HOME;
|
||||||
|
test_must_fail git config --get --path path.home \
|
||||||
|
>result 2>msg &&
|
||||||
|
git config --get --path path.normal >>result &&
|
||||||
|
git config --get --path path.trailingtilde >>result
|
||||||
|
) &&
|
||||||
|
grep "[Ff]ailed to expand.*~/" msg &&
|
||||||
|
test_cmp expect result
|
||||||
|
'
|
||||||
|
|
||||||
rm .git/config
|
rm .git/config
|
||||||
|
|
||||||
git config quote.leading " test"
|
git config quote.leading " test"
|
||||||
|
|
Loading…
Reference in New Issue