Skip to content

Commit ae0d079

Browse files
committed
Merge branch 'en/merge-recursive-fixes'
* en/merge-recursive-fixes: merge-recursive: add explanation for src_entry and dst_entry merge-recursive: fix logic ordering issue Tighten and correct a few testcases for merging and cherry-picking
2 parents cc7655a + 379fc37 commit ae0d079

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

merge-recursive.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,25 @@ static void record_df_conflict_files(struct merge_options *o,
513513

514514
struct rename {
515515
struct diff_filepair *pair;
516+
/*
517+
* Purpose of src_entry and dst_entry:
518+
*
519+
* If 'before' is renamed to 'after' then src_entry will contain
520+
* the versions of 'before' from the merge_base, HEAD, and MERGE in
521+
* stages 1, 2, and 3; dst_entry will contain the respective
522+
* versions of 'after' in corresponding locations. Thus, we have a
523+
* total of six modes and oids, though some will be null. (Stage 0
524+
* is ignored; we're interested in handling conflicts.)
525+
*
526+
* Since we don't turn on break-rewrites by default, neither
527+
* src_entry nor dst_entry can have all three of their stages have
528+
* non-null oids, meaning at most four of the six will be non-null.
529+
* Also, since this is a rename, both src_entry and dst_entry will
530+
* have at least one non-null oid, meaning at least two will be
531+
* non-null. Of the six oids, a typical rename will have three be
532+
* non-null. Only two implies a rename/delete, and four implies a
533+
* rename/add.
534+
*/
516535
struct stage_data *src_entry;
517536
struct stage_data *dst_entry;
518537
unsigned processed:1;
@@ -1998,10 +2017,10 @@ int merge_trees(struct merge_options *o,
19982017
get_files_dirs(o, merge);
19992018

20002019
entries = get_unmerged();
2001-
record_df_conflict_files(o, entries);
20022020
re_head = get_renames(o, head, common, head, merge, entries);
20032021
re_merge = get_renames(o, merge, common, head, merge, entries);
20042022
clean = process_renames(o, re_head, re_merge);
2023+
record_df_conflict_files(o, entries);
20052024
if (clean < 0)
20062025
goto cleanup;
20072026
for (i = entries->nr-1; 0 <= i; i--) {

t/t3501-revert-cherry-pick.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' '
141141
test_cmp expect actual
142142
'
143143

144-
test_expect_success 'cherry-pick works with dirty renamed file' '
144+
test_expect_failure 'cherry-pick works with dirty renamed file' '
145145
test_commit to-rename &&
146146
git checkout -b unrelated &&
147147
test_commit unrelated &&
@@ -150,7 +150,10 @@ test_expect_success 'cherry-pick works with dirty renamed file' '
150150
test_tick &&
151151
git commit -m renamed &&
152152
echo modified >renamed &&
153-
git cherry-pick refs/heads/unrelated
153+
test_must_fail git cherry-pick refs/heads/unrelated >out &&
154+
test_i18ngrep "Refusing to lose dirty file at renamed" out &&
155+
test $(git rev-parse :0:renamed) = $(git rev-parse HEAD^:to-rename.t) &&
156+
grep -q "^modified$" renamed
154157
'
155158

156159
test_done

t/t7607-merge-overwrite.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ test_expect_failure 'will not overwrite unstaged changes in renamed file' '
9797
git mv c1.c other.c &&
9898
git commit -m rename &&
9999
cp important other.c &&
100-
git merge c1a &&
100+
test_must_fail git merge c1a >out &&
101+
test_i18ngrep "Refusing to lose dirty file at other.c" out &&
102+
test_path_is_file other.c~HEAD &&
103+
test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) &&
101104
test_cmp important other.c
102105
'
103106

0 commit comments

Comments
 (0)