Skip to content

Commit 877c991

Browse files
committed
Merge branch 'bc/more-git-var'
Fix-up for a topic that already has graduated. * bc/more-git-var: var: avoid a segmentation fault when `HOME` is unset
2 parents 331f20d + 256a94e commit 877c991

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

builtin/var.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static char *git_attr_val_system(int ident_flag UNUSED)
6666

6767
static char *git_attr_val_global(int ident_flag UNUSED)
6868
{
69-
char *file = xstrdup(git_attr_global_file());
69+
char *file = xstrdup_or_null(git_attr_global_file());
7070
if (file) {
7171
normalize_path_copy(file, file);
7272
return file;

t/t0007-git-var.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,13 @@ test_expect_success 'listing and asking for variables are exclusive' '
268268
test_must_fail git var -l GIT_COMMITTER_IDENT
269269
'
270270

271+
test_expect_success '`git var -l` works even without HOME' '
272+
(
273+
XDG_CONFIG_HOME= &&
274+
export XDG_CONFIG_HOME &&
275+
unset HOME &&
276+
git var -l
277+
)
278+
'
279+
271280
test_done

0 commit comments

Comments
 (0)