Merge branch 'mh/blame-worktree'
authorJunio C Hamano <gitster@pobox.com>
Wed, 31 Aug 2016 17:03:50 +0000 (10:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 31 Aug 2016 17:03:50 +0000 (10:03 -0700)
* mh/blame-worktree:
blame: fix segfault on untracked files

builtin/blame.c
t/t8002-blame.sh
index 7ec782343002d27b1b7fdd7e61fada12e81eeaf1..a5bbf91e497524215c884f1e145070afcf3f586a 100644 (file)
@@ -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);
index ff09aced6855dbc9eaa963571b698919d7289871..ab79de95441f4f474525b48b14313f1d04172fce 100755 (executable)
@@ -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 \