Skip to content

Commit 4762bf3

Browse files
committed
Merge branch 'mh/blame-worktree'
* mh/blame-worktree: blame: fix segfault on untracked files
2 parents 9010077 + bc6b13a commit 4762bf3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

builtin/blame.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,8 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
22442244
pos = cache_name_pos(path, strlen(path));
22452245
if (pos >= 0)
22462246
; /* path is in the index */
2247-
else if (!strcmp(active_cache[-1 - pos]->name, path))
2247+
else if (-1 - pos < active_nr &&
2248+
!strcmp(active_cache[-1 - pos]->name, path))
22482249
; /* path is in the index, unmerged */
22492250
else
22502251
die("no such path '%s' in HEAD", path);

t/t8002-blame.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ test_description='git blame'
66
PROG='git blame -c'
77
. "$TEST_DIRECTORY"/annotate-tests.sh
88

9+
test_expect_success 'blame untracked file in empty repo' '
10+
>untracked &&
11+
test_must_fail git blame untracked
12+
'
13+
914
PROG='git blame -c -e'
1015
test_expect_success 'blame --show-email' '
1116
check_count \

0 commit comments

Comments
 (0)