blame $path: avoid getting fooled by case insensitive filesystems
[git.git] / builtin / blame.c
index 324d476abf18c3a71378aa44841026e42b4a0b88..83683b8287a365f4982770fa58f8cdb9084ea2c2 100644 (file)
@@ -2044,6 +2044,19 @@ static int git_blame_config(const char *var, const char *value, void *cb)
        return git_default_config(var, value, cb);
 }
 
+static void verify_working_tree_path(unsigned char *head_sha1, const char *path)
+{
+       unsigned char blob_sha1[20];
+       unsigned mode;
+
+       if (!resolve_ref_unsafe("HEAD", head_sha1, 1, NULL))
+               die("no such ref: HEAD");
+       if (get_tree_entry(head_sha1, path, blob_sha1, &mode))
+               die("no such path '%s' in HEAD", path);
+       if (sha1_object_info(blob_sha1, NULL) != OBJ_BLOB)
+               die("path '%s' in HEAD is not a blob", path);
+}
+
 /*
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
@@ -2062,8 +2075,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        struct cache_entry *ce;
        unsigned mode;
 
-       if (get_sha1("HEAD", head_sha1))
-               die("No such ref: HEAD");
+       verify_working_tree_path(head_sha1, path);
 
        time(&now);
        commit = xcalloc(1, sizeof(*commit));