Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-08-18 03:02:46 +0300
committerJunio C Hamano <gitster@pobox.com>2020-08-18 03:02:46 +0300
commitca81676a105dbd387c28fbcc428e8959990678ec (patch)
tree7a2fc7d8b19afd1cd616c4b54936cca96c325b4f /apply.c
parent47f0f94bc796037c43000a9852cdf9209a3c3274 (diff)
parent4c025c667ee29dd5e9260f423e8b0b3cc37e5e8c (diff)
Merge branch 'rp/apply-cached-with-i-t-a'
Recent versions of "git diff-files" shows a diff between the index and the working tree for "intent-to-add" paths as a "new file" patch; "git apply --cached" should be able to take "git diff-files" and should act as an equivalent to "git add" for the path, but the command failed to do so for such a path. * rp/apply-cached-with-i-t-a: t4140: test apply with i-t-a paths apply: make i-t-a entries never match worktree apply: allow "new file" patches on i-t-a entries
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/apply.c b/apply.c
index 402d80602a..57afee5120 100644
--- a/apply.c
+++ b/apply.c
@@ -3740,6 +3740,7 @@ static int check_preimage(struct apply_state *state,
#define EXISTS_IN_INDEX 1
#define EXISTS_IN_WORKTREE 2
+#define EXISTS_IN_INDEX_AS_ITA 3
static int check_to_create(struct apply_state *state,
const char *new_name,
@@ -3747,10 +3748,23 @@ static int check_to_create(struct apply_state *state,
{
struct stat nst;
- if (state->check_index &&
- index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&
- !ok_if_exists)
- return EXISTS_IN_INDEX;
+ if (state->check_index && (!ok_if_exists || !state->cached)) {
+ int pos;
+
+ pos = index_name_pos(state->repo->index, new_name, strlen(new_name));
+ if (pos >= 0) {
+ struct cache_entry *ce = state->repo->index->cache[pos];
+
+ /* allow ITA, as they do not yet exist in the index */
+ if (!ok_if_exists && !(ce->ce_flags & CE_INTENT_TO_ADD))
+ return EXISTS_IN_INDEX;
+
+ /* ITA entries can never match working tree files */
+ if (!state->cached && (ce->ce_flags & CE_INTENT_TO_ADD))
+ return EXISTS_IN_INDEX_AS_ITA;
+ }
+ }
+
if (state->cached)
return 0;
@@ -3935,6 +3949,9 @@ static int check_patch(struct apply_state *state, struct patch *patch)
case EXISTS_IN_INDEX:
return error(_("%s: already exists in index"), new_name);
break;
+ case EXISTS_IN_INDEX_AS_ITA:
+ return error(_("%s: does not match index"), new_name);
+ break;
case EXISTS_IN_WORKTREE:
return error(_("%s: already exists in working directory"),
new_name);