From: Jonathan Nieder Date: Mon, 26 Jul 2010 15:06:51 +0000 (-0500) Subject: config --get --path: check for unset $HOME X-Git-Tag: v1.7.0.7~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=79bf149061fa29482512d903192a0d929e82872b;p=git.git 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 Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- diff --git a/path.c b/path.c index aaa9345eb..f6226fcd5 100644 --- a/path.c +++ b/path.c @@ -316,6 +316,8 @@ char *expand_user_path(const char *path) size_t username_len = first_slash - username; if (username_len == 0) { const char *home = getenv("HOME"); + if (!home) + goto return_null; strbuf_add(&user_path, home, strlen(home)); } else { struct passwd *pw = getpw_str(username, username_len); diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index f11f98c3c..7ddab5fb7 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -707,19 +707,41 @@ test_expect_success 'set --path' ' git config --path path.trailingtilde "foo~" && test_cmp expect .git/config' +if test "${HOME+set}" +then + test_set_prereq HOMEVAR +fi + cat >expect < result && git config --get --path path.normal >> result && git config --get --path path.trailingtilde >> 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 git config quote.leading " test"