summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2016-08-31 10:03:50 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-08-31 10:03:50 -0700
commit4762bf36d9d4190dd7afdbc9ccc8bd8bc5af40f8 (patch)
tree99d9b401dbb6f5e27982ed9356a2820b84830bc3
parentMerge branch 'kw/patch-ids-optim' (diff)
parentblame: fix segfault on untracked files (diff)
downloadtgif-4762bf36d9d4190dd7afdbc9ccc8bd8bc5af40f8.tar.xz
Merge branch 'mh/blame-worktree'
* mh/blame-worktree: blame: fix segfault on untracked files
-rw-r--r--builtin/blame.c3
-rwxr-xr-xt/t8002-blame.sh5
2 files changed, 7 insertions, 1 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 7ec7823430..a5bbf91e49 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2244,7 +2244,8 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
pos = cache_name_pos(path, strlen(path));
if (pos >= 0)
; /* path is in the index */
- else if (!strcmp(active_cache[-1 - pos]->name, path))
+ else if (-1 - pos < active_nr &&
+ !strcmp(active_cache[-1 - pos]->name, path))
; /* path is in the index, unmerged */
else
die("no such path '%s' in HEAD", path);
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index ff09aced68..ab79de9544 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,6 +6,11 @@ test_description='git blame'
PROG='git blame -c'
. "$TEST_DIRECTORY"/annotate-tests.sh
+test_expect_success 'blame untracked file in empty repo' '
+ >untracked &&
+ test_must_fail git blame untracked
+'
+
PROG='git blame -c -e'
test_expect_success 'blame --show-email' '
check_count \