]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'bc/more-git-var' into maint-2.42
authorJunio C Hamano <gitster@pobox.com>
Thu, 2 Nov 2023 07:53:23 +0000 (16:53 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Nov 2023 07:53:23 +0000 (16:53 +0900)
Fix-up for a topic that already has graduated.

* bc/more-git-var:
  var: avoid a segmentation fault when `HOME` is unset

builtin/var.c
t/t0007-git-var.sh

index 74161bdf1c61b5248150bac284898e3c03c79111..8cf7dd9e2e5cef1d9238c22ed64ea07440d31528 100644 (file)
@@ -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;
index 8cb597f99c4cead2388681416d3cc0eddd90fa0f..ff4fd9348cca6470f4dbacbc4c9a3d775f15c06d 100755 (executable)
@@ -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