mirror of
https://github.com/git/git.git
synced 2024-11-29 04:54:56 +08:00
blame $path: avoid getting fooled by case insensitive filesystems
"git blame MAKEFILE" run in a history that has "Makefile" but not
MAKEFILE can get confused on a case insensitive filesystem, because
the check we run to see if there is a corresponding file in the
working tree with lstat("MAKEFILE") succeeds. In addition to that
check, we have to make sure that the given path also exists in the
commit we start digging history from (i.e. "HEAD").
Note that this reveals the breakage in a test added in cd8ae20
(git-blame shouldn't crash if run in an unmerged tree, 2007-10-18),
which expects the entire merge-in-progress path to be blamed to the
working tree when it did not exist in our tree. As it is clear in
the log message of that commit, the old breakage was that it was
causing an internal error and the fix was about avoiding it.
Just check that the command does not die an uncontrolled death. For
this particular case, the blame should fail, as the history for the
file in that contents has not been committed yet at the point in the
test.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
785ee4960c
commit
ffcabccf5d
@ -2044,6 +2044,19 @@ static int git_blame_config(const char *var, const char *value, void *cb)
|
|||||||
return git_default_config(var, value, 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.
|
* Prepare a dummy commit that represents the work tree (or staged) item.
|
||||||
* Note that annotating work tree item never works in the reverse.
|
* 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;
|
struct cache_entry *ce;
|
||||||
unsigned mode;
|
unsigned mode;
|
||||||
|
|
||||||
if (get_sha1("HEAD", head_sha1))
|
verify_working_tree_path(head_sha1, path);
|
||||||
die("No such ref: HEAD");
|
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
commit = xcalloc(1, sizeof(*commit));
|
commit = xcalloc(1, sizeof(*commit));
|
||||||
|
@ -66,8 +66,8 @@ test_expect_success \
|
|||||||
git blame file2
|
git blame file2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'blame runs on conflicted file in stages 1,3' '
|
test_expect_success 'blame does not crash with conflicted file in stages 1,3' '
|
||||||
git blame file1
|
test_must_fail git blame file1
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user