diff options
Diffstat (limited to 'merge-ort.c')
-rw-r--r-- | merge-ort.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/merge-ort.c b/merge-ort.c index e5f41cce48..2cbca60e6c 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2619,8 +2619,40 @@ static void apply_directory_rename_modifications(struct merge_options *opt, } assert(ci->filemask == 2 || ci->filemask == 4); - assert(ci->dirmask == 0); - strmap_remove(&opt->priv->paths, old_path, 0); + assert(ci->dirmask == 0 || ci->dirmask == 1); + if (ci->dirmask == 0) + strmap_remove(&opt->priv->paths, old_path, 0); + else { + /* + * This file exists on one side, but we still had a directory + * at the old location that we can't remove until after + * processing all paths below it. So, make a copy of ci in + * new_ci and only put the file information into it. + */ + new_ci = mem_pool_calloc(&opt->priv->pool, 1, sizeof(*new_ci)); + memcpy(new_ci, ci, sizeof(*ci)); + assert(!new_ci->match_mask); + new_ci->dirmask = 0; + new_ci->stages[1].mode = 0; + oidcpy(&new_ci->stages[1].oid, null_oid()); + + /* + * Now that we have the file information in new_ci, make sure + * ci only has the directory information. + */ + ci->filemask = 0; + ci->merged.clean = 1; + for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) { + if (ci->dirmask & (1 << i)) + continue; + /* zero out any entries related to files */ + ci->stages[i].mode = 0; + oidcpy(&ci->stages[i].oid, null_oid()); + } + + // Now we want to focus on new_ci, so reassign ci to it + ci = new_ci; + } branch_with_new_path = (ci->filemask == 2) ? opt->branch1 : opt->branch2; branch_with_dir_rename = (ci->filemask == 2) ? opt->branch2 : opt->branch1; |