diff options
author | Paul Tan <pyokagan@gmail.com> | 2015-06-11 18:21:56 +0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-06-14 15:36:31 -0700 |
commit | 177ee4942f788f832e4fb6bbf9a5442d396db263 (patch) | |
tree | de930cfd921cd628870e1c0501945ce8dd82fa8c | |
parent | fb1654de7a5929db773268011d50c24561504bea (diff) | |
download | git-177ee4942f788f832e4fb6bbf9a5442d396db263.tar.gz |
am: refresh the index at start
If a file is unchanged but stat-dirty, git-apply may erroneously fail to
apply patches, thinking that they conflict with a dirty working tree.
As such, since 2a6f08a (am: refresh the index at start and --resolved,
2011-08-15), git-am will refresh the index before applying patches.
Re-implement this behavior.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
-rw-r--r-- | builtin/am.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/builtin/am.c b/builtin/am.c index ecc6d29f13..417bfde159 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -13,6 +13,7 @@ #include "cache-tree.h" #include "refs.h" #include "commit.h" +#include "lockfile.h" /** * Returns 1 if the file is empty or does not exist, 0 otherwise. @@ -457,6 +458,20 @@ static const char *msgnum(const struct am_state *state) } /** + * Refresh and write index. + */ +static void refresh_and_write_cache(void) +{ + static struct lock_file lock_file; + + hold_locked_index(&lock_file, 1); + refresh_cache(REFRESH_QUIET); + if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) + die(_("unable to write index file")); + rollback_lock_file(&lock_file); +} + +/** * Parses `patch` using git-mailinfo. state->msg will be set to the patch * message. state->author_name, state->author_email, state->author_date will be * set to the patch author's name, email and date respectively. The patch's @@ -597,6 +612,8 @@ static void do_commit(const struct am_state *state) */ static void am_run(struct am_state *state) { + refresh_and_write_cache(); + while (state->cur <= state->last) { const char *patch = am_path(state, msgnum(state)); @@ -678,6 +695,9 @@ int cmd_am(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, am_options, am_usage, 0); + if (read_index_preload(&the_index, NULL) < 0) + die(_("failed to read the index")); + if (am_in_progress(&state)) am_load(&state); else { |