summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2016-07-16 08:23:45 +0900
committerJunio C Hamano <gitster@pobox.com>2016-07-18 14:33:38 -0700
commit3b75ee93278179004bc2f117fcfe3d5d76a0a2fa (patch)
tree86f8d5603b6030f76206ec1f1beac1eb3d6ff45b /builtin
parent0b65a8dbdb38962e700ee16776a3042beb489060 (diff)
downloadgit-3b75ee93278179004bc2f117fcfe3d5d76a0a2fa.tar.gz
blame: allow to blame paths freshly added to the index
When blaming files, changes in the work tree are taken into account and displayed as being "Not Committed Yet". However, when blaming a file that is not known to the current HEAD, git blame fails with `no such path 'foo' in HEAD`, even when the file was git add'ed. Allowing such a blame is useful when the new file added to the index (not yet committed) was created by renaming an existing file. It also is useful when the new file was created from pieces already in HEAD, moved or copied from other files and blaming with copy detection (i.e. "-C"). Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/blame.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 21f42b0b62..12c765acfe 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2230,6 +2230,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
static void verify_working_tree_path(struct commit *work_tree, const char *path)
{
struct commit_list *parents;
+ int pos;
for (parents = work_tree->parents; parents; parents = parents->next) {
const unsigned char *commit_sha1 = parents->item->object.oid.hash;
@@ -2240,7 +2241,14 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
sha1_object_info(blob_sha1, NULL) == OBJ_BLOB)
return;
}
- die("no such path '%s' in HEAD", 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))
+ ; /* path is in the index, unmerged */
+ else
+ die("no such path '%s' in HEAD", path);
}
static struct commit_list **append_parent(struct commit_list **tail, const unsigned char *sha1)