diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2007-09-17 01:24:57 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-16 18:20:10 -0700 |
commit | ece7b74903007cee8d280573647243d46a6f3a95 (patch) | |
tree | 768d9bc4eaf26d832cc4f566385055e20f19dd39 /builtin-apply.c | |
parent | f3caeb9ac2ea13cf113183540f32fbc4c0468ed5 (diff) | |
download | git-ece7b74903007cee8d280573647243d46a6f3a95.tar.gz |
apply --index-info: fall back to current index for mode changes
"git diff" does not record index lines for pure mode changes (i.e. no
lines changed). Therefore, apply --index-info would call out a bogus
error.
Instead, fall back to reading the info from the current index.
Incidentally, this fixes an error where git-rebase would not rebase a
commit including a pure mode change, and changes requiring a threeway
merge.
Noticed and later tested by Chris Shoemaker.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-apply.c')
-rw-r--r-- | builtin-apply.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/builtin-apply.c b/builtin-apply.c index 976ec77041..f4ecf03ed4 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2227,6 +2227,20 @@ static int check_patch_list(struct patch *patch) return err; } +/* This function tries to read the sha1 from the current index */ +static int get_current_sha1(const char *path, unsigned char *sha1) +{ + int pos; + + if (read_cache() < 0) + return -1; + pos = cache_name_pos(path, strlen(path)); + if (pos < 0) + return -1; + hashcpy(sha1, active_cache[pos]->sha1); + return 0; +} + static void show_index_list(struct patch *list) { struct patch *patch; @@ -2243,8 +2257,16 @@ static void show_index_list(struct patch *list) if (0 < patch->is_new) sha1_ptr = null_sha1; else if (get_sha1(patch->old_sha1_prefix, sha1)) - die("sha1 information is lacking or useless (%s).", - name); + /* git diff has no index line for mode/type changes */ + if (!patch->lines_added && !patch->lines_deleted) { + if (get_current_sha1(patch->new_name, sha1) || + get_current_sha1(patch->old_name, sha1)) + die("mode change for %s, which is not " + "in current HEAD", name); + sha1_ptr = sha1; + } else + die("sha1 information is lacking or useless " + "(%s).", name); else sha1_ptr = sha1; |