diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-11-02 16:53:23 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-11-02 16:53:23 +0900 |
commit | 535b30eb58a19a9f006c5e88cbe9f3a13118ab94 (patch) | |
tree | 54c67afb753e3054eacf226f7dd4bd1a1134bc04 | |
parent | 0510d06b56dfe25376cc9e9ee10b565241931f8d (diff) | |
parent | 256a94ef6c8c0c94f9629a1ffe893577ccef8efd (diff) | |
download | git-535b30eb58a19a9f006c5e88cbe9f3a13118ab94.tar.gz |
Merge branch 'bc/more-git-var' into maint-2.42
Fix-up for a topic that already has graduated.
* bc/more-git-var:
var: avoid a segmentation fault when `HOME` is unset
-rw-r--r-- | builtin/var.c | 2 | ||||
-rwxr-xr-x | t/t0007-git-var.sh | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/builtin/var.c b/builtin/var.c index 74161bdf1c..8cf7dd9e2e 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -66,7 +66,7 @@ static char *git_attr_val_system(int ident_flag UNUSED) static char *git_attr_val_global(int ident_flag UNUSED) { - char *file = xstrdup(git_attr_global_file()); + char *file = xstrdup_or_null(git_attr_global_file()); if (file) { normalize_path_copy(file, file); return file; diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh index 8cb597f99c..ff4fd9348c 100755 --- a/t/t0007-git-var.sh +++ b/t/t0007-git-var.sh @@ -268,4 +268,13 @@ test_expect_success 'listing and asking for variables are exclusive' ' test_must_fail git var -l GIT_COMMITTER_IDENT ' +test_expect_success '`git var -l` works even without HOME' ' + ( + XDG_CONFIG_HOME= && + export XDG_CONFIG_HOME && + unset HOME && + git var -l + ) +' + test_done |