Work-in-progress merge-recursive work
cover Work-in-progress merge-recursive work
This is a set of changes I was working on last Sept-Nov; these changes are not ready for git.git (other than perhaps patches 1 and 5), but I figured it might be useful to send anyway because (1) it might serve as notification to others of various edge and corner case issues that exist, and (2) the work won't die if my laptop harddrive does.
I'm expecting to clean these up, though it may take me a month or two before I get the time.
(Note that patch 5 contains a subset of b9b3eef (merge-recursive:
tweak magic band-aid 2011-03-17); I could have saved Junio some time if I had submitted that earlier, and had remembered that change instead of propagating the mistake. Sorry about that.)
Most of what is included are new testcases exposing edge and corner case bugs in merge-recursive that I found in a code audit, some of which are marked as test_expect_success even though the test does not succeed. There may be a few tests that are just cases I was testing for completeness or that I was worried about breaking with planned changes. I didn't try to figure out the right place to add all these tests (we're out of space in the t60[23]x range and I wasn't sure if I wanted to dump all of these into t6036), so I just named them tempxx.sh.
Elijah Newren (10):
merge-recursive: Remove redundant check for removing rename source Reminder to fix o->call_depth handling in conflict_rename_rename_1to2 A bunch of fixes and FIXMEs
Correct a comment
merge-recursive: Fix sorting order and directory change assumptions Add a comment pointing out a bug
Good testcases
More test scripts
Tests and fixes associated with rename/rename conflicts Add new testcase (temp14) showing how undetected renames can cause or
spuriously avoid merge conflicts
merge-recursive.c | 86 ++++++++++++++++++++++-------- t/t6020-merge-df.sh | 26 ++++++--- t/temp1.sh | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++ t/temp10.sh | 41 ++++++++++++++ t/temp11.sh | 41 ++++++++++++++ t/temp12.sh | 59 +++++++++++++++++++++ t/temp13.sh | 79 +++++++++++++++++++++++++++ t/temp14.sh | 63 ++++++++++++++++++++++ t/temp2.sh | 86 ++++++++++++++++++++++++++++++ t/temp3.sh | 72 +++++++++++++++++++++++++ t/temp4.sh | 96 +++++++++++++++++++++++++++++++++ t/temp5.sh | 35 ++++++++++++ t/temp50.sh | 38 +++++++++++++ t/temp6.sh | 55 +++++++++++++++++++ t/temp7.sh | 34 ++++++++++++ t/temp8.sh | 37 +++++++++++++ t/temp9.sh | 73 +++++++++++++++++++++++++ 17 files changed, 1036 insertions(+), 31 deletions(-) create mode 100644 t/temp1.sh create mode 100755 t/temp10.sh create mode 100755 t/temp11.sh create mode 100755 t/temp12.sh create mode 100755 t/temp13.sh create mode 100755 t/temp14.sh create mode 100755 t/temp2.sh create mode 100755 t/temp3.sh create mode 100755 t/temp4.sh create mode 100755 t/temp5.sh create mode 100755 t/temp50.sh create mode 100755 t/temp6.sh create mode 100755 t/temp7.sh create mode 100755 t/temp8.sh create mode 100755 t/temp9.sh
Signature · 1 line
1.7.4
PATCH 1/10 merge-recursive: Remove redundant check for removing rename source
If a file is renamed on the side of history being merged into head, the filename serving as the source of that rename needs to be removed from the working directory. (This statement is about a real merge rather than a merge of merge bases to come up with a virtual ancestor; in the latter case, no working directory changes of any type should be made).
The path to getting the above statement implemented in merge-recursive took several steps. The relevant bits of code may be instructive to keep in mind for the explanation, especially since an English-only description involves double negatives that are hard to follow. These bits of code are:
int remove_file(..., const char *path, int no_wd)
{
...
int update_working_directory = !o->call_depth && !no_wd;and
remove_file(o, 1, ren1_src, <expression>);
Where the choice for <expression> has morphed over time:
65ac6e9 (merge-recursive: adjust to loosened "working file clobbered" check 2006-10-27), introduced the "no_wd" parameter to remove_file() and used "1" for <expression>. This meant ren1_src was never deleted, leaving it around in the working copy.
In 8371234 (Remove uncontested renamed files during merge. 2006-12-13), <expression> was changed to "index_only" (where index_only ==
!!o->call_depth; see b7fa51da). This was equivalent to using "0" for
<expression> (due to the early logic in remove_file), and is orthogonal to the condition we actually want to check at this point; it resulted in the source file being removed except when index_only was false. This was problematic because the file could have been renamed on the side of history including head, in which case ren1_src could correspond to an untracked file that should not be deleted.
In 183d797 (Keep untracked files not involved in a merge. 2007-02-04), <expression> was changed to "index_only || stage == 3". While this gives correct behavior, the "index_only ||" portion of <expression> is unnecessary and makes the code slightly harder to follow.
There were also two further changes to this expression, though without any change in behavior. First in b7fa51d (merge-recursive: get rid of the index_only global variable 2008-09-02), it was changed to "o->call_depth || stage == 3". (index_only == !!o->call_depth). Earlier in this series (merge-recursive: Small code clarification -- variable name and comments), this was changed to "o->call_depth || renamed_stage == 2" (where stage was renamed to other_stage and renamed_stage == other_stage ^ 1).
So we ended with <expression> being "o->call_depth || renamed_stage == 2". But the "o->call_depth ||" piece was unnecessary. Remove it.
--- merge-recursive.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
merge-recursive.c +1 -1
@@ -1055,7 +1055,7 @@ static int process_renames(struct merge_options *o,int renamed_stage = a_renames == renames1 ?2 :3 ;int other_stage = a_renames == renames1 ?3 :2 ; -remove_file (o,1 , ren1_src, o->call_depth || renamed_stage ==2 ); +remove_file (o,1 , ren1_src, renamed_stage ==2 );hashcpy (src_other.sha1, ren1->src_entry->stages[other_stage].sha); src_other.mode = ren1->src_entry->stages[other_stage].mode;
Signature · 1 line
1.7.4
PATCH 2/10 Reminder to fix o->call_depth handling in conflict_rename_rename_1to2
In reply to Elijah Newren--- merge-recursive.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
merge-recursive.c +4 -0
@@ -908,6 +908,10 @@ static void conflict_rename_rename_1to2(struct merge_options *o, ren2_dst, branch1, dst_name2); }if (o->call_depth) { +/* +* FIXME: This is bogus. dst_nameX are not in cache in +* case of D/F conflict. +*/ remove_file_from_cache (dst_name1);remove_file_from_cache (dst_name2);/*
Signature · 1 line
1.7.4
PATCH 3/10 A bunch of fixes and FIXMEs
In reply to Elijah Newren--- merge-recursive.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
merge-recursive.c +12 -4
@@ -910,7 +910,8 @@ static void conflict_rename_rename_1to2(struct merge_options *o,if (o->call_depth) {/* * FIXME: This is bogus. dst_nameX are not in cache in -* case of D/F conflict. +* case of D/F conflict. renX_dst are. Simple typo, or +* something worse? */ remove_file_from_cache (dst_name1);remove_file_from_cache (dst_name2);
@@ -1290,10 +1291,12 @@ static int merge_content(struct merge_options *o,const char *new_path;update_file_flags (o, mfi.sha, mfi.mode, path, o->call_depth || mfi.clean,0 ); - new_path =unique_path (o, path, df_rename_conflict_branch); mfi.clean =0 ; -output (o,1 ,"Adding as %s instead" , new_path); -update_file_flags (o, mfi.sha, mfi.mode, new_path,0 ,1 ); +if (!o->call_depth) { + new_path =unique_path (o, path, df_rename_conflict_branch); +output (o,1 ,"Adding as %s instead" , new_path); +update_file (o, mfi.clean, mfi.sha, mfi.mode, new_path); + } }else {update_file (o, mfi.clean, mfi.sha, mfi.mode, path); }
@@ -1433,6 +1436,11 @@ static int process_df_entry(struct merge_options *o, src, conflict_info->pair2->two->path, conflict_info->branch2, o->call_depth ? " (left unresolved)" : "");if (o->call_depth) { +/* +* FIXME: Why remove file from cache, and +* then immediately readd it? Why not just +* overwrite using update_file only? +*/ remove_file_from_cache (src);update_file (o,0 , conflict_info->pair1->one->sha1, conflict_info->pair1->one->mode, src);
Signature · 1 line
1.7.4
PATCH 4/10 Correct a comment
In reply to Elijah Newren--- merge-recursive.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
merge-recursive.c +1 -1
@@ -1464,7 +1464,7 @@ static int process_df_entry(struct merge_options *o,handle_delete_modify (o, path, new_path, a_sha, a_mode, b_sha, b_mode); }else if (!o_sha && !!a_sha != !!b_sha) { -/* directory -> (directory, file) */ +/* directory -> (directory, file) or <nothing> -> (directory, file) */ const char *add_branch;const char *other_branch;unsigned mode;
Signature · 1 line
1.7.4
PATCH 5/10 merge-recursive: Fix sorting order and directory change assumptions
In reply to Elijah NewrenAs pointed out in the review of my earlier series, we cannot assume that directory/file conflicts will appear in sorted order; for example, 'letters.txt' comes between 'letters' and 'letters/file'.
Also, we should not make changes to the working directory when merging merge-bases, so removing files to make room for directories of d/f conflicts should be skipped in such cases.
(These changes were made last September/October, but were mixed in with an update of my series that I never got around to resubmitting. Now that the original series was accepted, I split these changes back out.)
--- merge-recursive.c | 38 +++++++++++++++++++++++++++++++++----- t/t6020-merge-df.sh | 26 ++++++++++++++++++-------- 2 files changed, 51 insertions(+), 13 deletions(-)
merge-recursive.c +33 -5
@@ -344,6 +344,28 @@ static struct string_list *get_unmerged(void)return unmerged; } +static int string_list_df_name_compare (const void *a,const void *b) +{ +const struct string_list_item *one = a; +const struct string_list_item *two = b; +/* +* Here we only care that entries for D/F conflicts are +* adjacent, in particular with the file of the D/F conflict +* appearing before files below the corresponding directory. +* The order of the rest of the list is irrelevant for us. +* +* To achieve this, we sort with df_name_compare and provide +* the mode S_IFDIR so that D/F conflicts will sort correctly. +* We use the mode S_IFDIR for everything else for simplicity, +* since in other cases any changes in their order due to +* sorting cause no problems for us. +*/ +return df_name_compare (one->string,strlen (one->string),S_IFDIR , + two->string,strlen (two->string),S_IFDIR ); +} + + +static void make_room_for_directories_of_df_conflicts (struct merge_options *o,struct string_list *entries) {
@@ -356,17 +378,23 @@ static void make_room_for_directories_of_df_conflicts(struct merge_options *o,* otherwise, if the file is not supposed to be removed by the * merge, the contents of the file will be placed in another * unique filename. -* -* NOTE: This function relies on the fact that entries for a -* D/F conflict will appear adjacent in the index, with the -* entries for the file appearing before entries for paths -* below the corresponding directory. */ const char *last_file =NULL ;int last_len =0 ;struct stage_data *last_e;int i; +/* +* If we're merging merge-bases, we don't want to bother with +* any working directory changes. +*/ +if (o->call_depth) +return ; + +/* Ensure D/F conflicts are adjacent in the entries list. */ +qsort (entries->items, entries->nr,sizeof (*entries->items), + string_list_df_name_compare); +for (i =0 ; i < entries->nr; i++) {const char *path = entries->items[i].string;int len =strlen (path);
t/t6020-merge-df.sh +18 -8
@@ -59,15 +59,19 @@ test_expect_success 'setup modify/delete + directory/file conflict' ' git add letters && git commit -m initial && + # Throw in letters.txt for sorting order fun + # ("letters.txt" sorts between "letters" and "letters/file") echo i >>letters && - git add letters && + echo "version 2" >letters.txt && + git add letters letters.txt && git commit -m modified && git checkout -b delete HEAD^ && git rm letters && mkdir letters && >letters/file && - git add letters && + echo "version 1" >letters.txt && + git add letters letters.txt && git commit -m deleted '
@@ -75,25 +79,31 @@ test_expect_success 'modify/delete + directory/file conflict' ' git checkout delete^0 && test_must_fail git merge modify && - test 3 = $(git ls-files -s | wc -l) && - test 2 = $(git ls-files -u | wc -l) && - test 1 = $(git ls-files -o | wc -l) && + test 5 -eq $(git ls-files -s | wc -l) && + test 4 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && test -f letters/file && + test -f letters.txt && test -f letters~modify ' test_expect_success 'modify/delete + directory/file conflict; other way' ' + # Yes, we really need the double reset since "letters" appears as + # both a file and a directory. + git reset --hard && git reset --hard && git clean -f && git checkout modify^0 && + test_must_fail git merge delete && - test 3 = $(git ls-files -s | wc -l) && - test 2 = $(git ls-files -u | wc -l) && - test 1 = $(git ls-files -o | wc -l) && + test 5 -eq $(git ls-files -s | wc -l) && + test 4 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && test -f letters/file && + test -f letters.txt && test -f letters~HEAD '
Signature · 1 line
1.7.4
PATCH 6/10 Add a comment pointing out a bug
In reply to Elijah Newren--- merge-recursive.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
merge-recursive.c +1 -1
@@ -1064,7 +1064,7 @@ static int process_renames(struct merge_options *o, ren1->dst_entry, ren2->dst_entry); }else { -remove_file (o,1 , ren1_src,1 ); +remove_file (o,1 , ren1_src,1 );// BAD update_stages_and_entry(ren1_dst, ren1->dst_entry, ren1->pair->one,
Signature · 1 line
1.7.4
PATCH 7/10 Good testcases
In reply to Elijah Newren--- t/temp1.sh | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/temp2.sh | 86 +++++++++++++++++++++++++++++++++++ t/temp3.sh | 72 +++++++++++++++++++++++++++++ t/temp4.sh | 96 +++++++++++++++++++++++++++++++++++++++ t/temp5.sh | 35 ++++++++++++++ t/temp6.sh | 55 ++++++++++++++++++++++ t/temp7.sh | 34 ++++++++++++++ t/temp8.sh | 37 +++++++++++++++ 8 files changed, 561 insertions(+), 0 deletions(-) create mode 100644 t/temp1.sh create mode 100755 t/temp2.sh create mode 100755 t/temp3.sh create mode 100755 t/temp4.sh create mode 100755 t/temp5.sh create mode 100755 t/temp6.sh create mode 100755 t/temp7.sh create mode 100755 t/temp8.sh
t/temp1.sh new file +146 -0
@@ -0,0 +1,146 @@ +#!/bin/sh + +test_description='recursive merge corner cases: d/f conflict (via add/add) + criss-cross merge' + +. ./test-lib.sh + +# +# Let's make it a bit more coplicated: +# Commit A: Neither file 'a' nor directory 'a/' exist. +# Commit B: Introduce 'a' +# Commit C: Introduce 'a/file' +# Two different later cases: +# Commit D1: Merge B & C, keeping 'a' and deleting 'a/' +# Commit E1: Merge B & C, deleting 'a' but keeping 'a/file' +# +# Commit D2: Merge B & C, keeping a modified 'a' and deleting 'a/' +# Commit E2: Merge B & C, deleting 'a' but keeping a modified 'a/file' +# Finally, someone goes to merge D1&E1 or D1&E2 or D2&E1. What happens? +# +# B D1 or D2 +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E1 or E2 +# + +test_expect_success 'setup differently handled merges of directory/file conflict' ' + >irrelevant-file && + git add irrelevant-file && + test_tick && + git commit -m A && + + git branch B && + git checkout -b C && + mkdir a && + echo 10 >a/file && + git add a/file && + test_tick && + git commit -m C && + + git checkout B && + echo 5 >a && + git add a && + test_tick && + git commit -m B && + + git checkout B^0 && + test_must_fail git merge C && + git clean -f && + rm -rf a/ && + echo 5 >a && + git add a && + test_tick && + git commit -m D && + git tag D && + + git checkout C^0 && + test_must_fail git merge B && + git clean -f && + echo 10 >a/file && + git add a/file && + git rm --cached a && + test_tick && + git commit -m E1 && + git tag E1 && + + git checkout C^0 && + test_must_fail git merge B && + git clean -f && + printf "10\n11\n" >a/file && + git add a/file && + git rm --cached a && + test_tick && + git commit -m E2 && + git tag E2 +' + +test_expect_success 'git detects conflict and handles merge of D & E1 correctly' ' + git reset --hard && + git reset --hard && + git clean -fdqx && + git checkout D^0 && + + test_must_fail git merge -s recursive E1^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :2:a) = $(git rev-parse B:a) && + test $(git rev-parse :3:a/file) = $(git rev-parse C:a/file) +' + +test_expect_failure 'git detects conflict and handles merge of E1 & D correctly' ' + git reset --hard && + git reset --hard && + git clean -fdqx && + git checkout E1^0 && + + test_must_fail git merge -s recursive D^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :3:a) = $(git rev-parse B:a) && + test $(git rev-parse :2:a/file) = $(git rev-parse C:a/file) +' + +test_expect_success 'git detects conflict and handles merge of D & E2 correctly' ' + git reset --hard && + git reset --hard && + git clean -fdqx && + git checkout D^0 && + + test_must_fail git merge -s recursive E2^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :2:a) = $(git rev-parse B:a) && + test $(git rev-parse :3:a/file) = $(git rev-parse E1:a/file) + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) +' + +test_expect_success 'git detects conflict and handles merge of E2 & D correctly' ' + git reset --hard && + git reset --hard && + git clean -fdqx && + git checkout E2^0 && + + test_must_fail git merge -s recursive D^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :3:a) = $(git rev-parse B:a) && + test $(git rev-parse :2:a/file) = $(git rev-parse E1:a/file) + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) +' + +test_done
t/temp2.sh new file +86 -0
86 lines not on this page · raw message
t/temp3.sh new file +72 -0
72 lines not on this page · raw message
t/temp4.sh new file +96 -0
96 lines not on this page · raw message
t/temp5.sh new file +35 -0
@@ -0,0 +1,35 @@ +#!/bin/sh + +test_description="Does git preserve Gollum's precious artifact?" + +. ./test-lib.sh + +test_expect_success 'setup abbreviated storyline' ' + echo "A pretty inscription" >ring && + git add ring && + test_tick && + git commit -m beginning && + + git branch people && + git checkout -b rename-the-ring && + git mv ring one-ring-to-rule-them-all && + test_tick && + git commit -m fullname && + + git checkout people && + git rm ring && + echo gollum >owner && + git add owner && + test_tick && + git commit -m track-people-instead-of-objects && + echo "Myyy PRECIOUSSS" >ring +' + +test_expect_success 'Does git preserve the ring?' ' + test_must_fail git merge -s recursive rename-the-ring && + + # Make sure git did not delete an untracked file + test -f ring +' + +test_done
t/temp6.sh new file +55 -0
55 lines not on this page · raw message
t/temp7.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/bin/sh + +test_description="File renamed identically on both sides + re-add source name" + +. ./test-lib.sh + +test_expect_success 'setup rename/rename/add resolvable conflict' ' + >a && + git add a && + test_tick && + git commit -m base && + git tag base && + + git checkout -b one base && + git mv a b && + test_tick && + git commit -m one && + + git checkout -b two base && + git mv a b && + echo important-info >a && + test_tick && + git commit -m two +' + +test_expect_success 'merge include important info in new a' ' + git checkout two^0 && + git merge -s recursive one^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) +' + +test_done
t/temp8.sh new file +37 -0
@@ -0,0 +1,37 @@ +#!/bin/sh + +test_description="Rename/rename/add conflict" + +. ./test-lib.sh + +test_expect_success 'setup rename/rename (1to2) + add conflict' ' + echo stuff >a && + git add a && + test_tick && + git commit -m base && + git tag base && + + git checkout -b one base && + git mv a b && + echo precious-data >c && + git add c && + test_tick && + git commit -m one && + + git checkout -b two base && + git mv a c && + echo important-info >b && + git add b && + test_tick && + git commit -m two +' + +test_expect_success 'merge maintains important data from one:c and two:b' ' + git checkout two^0 && + test_must_fail git merge -s recursive one^0 && + + test 2 -eq $(git ls-files -u b | wc -l) && + test 2 -eq $(git ls-files -u c | wc -l) +' + +test_done
Signature · 1 line
1.7.4
PATCH 8/10 More test scripts
In reply to Elijah Newren--- t/temp10.sh | 41 +++++++++++++++++++++++++++++++++ t/temp11.sh | 41 +++++++++++++++++++++++++++++++++ t/temp50.sh | 38 ++++++++++++++++++++++++++++++ t/temp9.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+), 0 deletions(-) create mode 100755 t/temp10.sh create mode 100755 t/temp11.sh create mode 100755 t/temp50.sh create mode 100755 t/temp9.sh
t/temp10.sh new file +41 -0
@@ -0,0 +1,41 @@ +#!/bin/sh + +test_description='merge+diff issue: rename/add vs. copy/modify' + +. ./test-lib.sh + +# Testcase setup: +# Commit A: new file: a +# Commit B: modify a slightly +# Commit C: rename a->b, add completely different a +# +# We should be able to merge B & C cleanly + +test_expect_success 'setup modify + rename/add(source) merge' ' + printf "1\n2\n3\n4\n5\n6\n7\n" >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + echo 8 >>a && + git add a && + git commit -m B && + + git checkout -b C A && + git mv a b && + echo something completely different >a && + git add a && + git commit -m C +' + +test_expect_success 'no conflict merging B & C' ' + git checkout B^0 && + + git merge -s recursive C^0 && + + test $(git rev-parse B:a) = $(git rev-parse b) && + test $(git rev-parse C:a) = $(git rev-parse a) +' + +test_done
t/temp11.sh new file +41 -0
41 lines not on this page · raw message
t/temp50.sh new file +38 -0
@@ -0,0 +1,38 @@ +#!/bin/sh + +test_description="Rename/rename conflict doesn't leave files in place for user" + +. ./test-lib.sh + +test_expect_success 'setup rename/rename (1to2) conflict' ' + echo stuff >a && + git add a && + test_tick && + git commit -m base && + git tag base && + + git checkout -b one base && + git mv a b && + test_tick && + git commit -m one && + + git checkout -b two base && + git mv a c && + test_tick && + git commit -m two +' + +test_expect_success 'merge has correct working tree contents' ' + git checkout two^0 && + + test_must_fail git merge -s recursive one^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 3 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test -f b && + test -f c +' + +test_done
t/temp9.sh new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 9/10 Tests and fixes associated with rename/rename conflicts
In reply to Elijah NewrenAdd a new testcase for basic rename/rename (+modify/modify) -- temp12 Add a testcase for tough-to-handle rename/rename + criss-cross merges
Fix up most of temp12 testcase, but not yet handling merging of info from other side of history.
--- merge-recursive.c | 24 ++++++++-------- t/temp12.sh | 59 +++++++++++++++++++++++++++++++++++++++ t/temp13.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 12 deletions(-) create mode 100755 t/temp12.sh create mode 100755 t/temp13.sh
merge-recursive.c +12 -12
@@ -991,12 +991,12 @@ static int process_renames(struct merge_options *o,for (i =0 ; i < a_renames->nr; i++) { sre = a_renames->items[i].util;string_list_insert (&a_by_dst, sre->pair->two->path)->util - = sre->dst_entry; + = (void *)sre; }for (i =0 ; i < b_renames->nr; i++) { sre = b_renames->items[i].util;string_list_insert (&b_by_dst, sre->pair->two->path)->util - = sre->dst_entry; + = (void *)sre; }for (i =0 , j =0 ; i < a_renames->nr || j < b_renames->nr;) {
@@ -1110,6 +1110,16 @@ static int process_renames(struct merge_options *o, clean_merge =0 ;conflict_rename_delete (o, ren1->pair, branch1, branch2); } + }else if ((item =string_list_lookup (renames2Dst, ren1_dst))) { + ren2 = item->util; + clean_merge =0 ; + ren2->processed =1 ; +output (o,1 ,"CONFLICT (rename/rename): " +"Rename %s->%s in %s. " +"Rename %s->%s in %s" , + ren1_src, ren1_dst, branch1, + ren2->pair->one->path, ren2->pair->two->path, branch2); +conflict_rename_rename_2to1 (o, ren1, branch1, ren2, branch2); }else if ((dst_other.mode == ren1->pair->two->mode) &&sha_eq (dst_other.sha1, ren1->pair->two->sha1)) {/* Added file on the other side
@@ -1150,16 +1160,6 @@ static int process_renames(struct merge_options *o,output (o,1 ,"Adding as %s instead" , new_path);update_file (o,0 , dst_other.sha1, dst_other.mode, new_path); } - }else if ((item =string_list_lookup (renames2Dst, ren1_dst))) { - ren2 = item->util; - clean_merge =0 ; - ren2->processed =1 ; -output (o,1 ,"CONFLICT (rename/rename): " -"Rename %s->%s in %s. " -"Rename %s->%s in %s" , - ren1_src, ren1_dst, branch1, - ren2->pair->one->path, ren2->pair->two->path, branch2); -conflict_rename_rename_2to1 (o, ren1, branch1, ren2, branch2); }else try_merge =1 ;
t/temp12.sh new file +59 -0
59 lines not on this page · raw message
t/temp13.sh new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 10/10 Add new testcase (temp14) showing how undetected renames can cause or spuriously avoid merge conflicts
In reply to Elijah Newren--- t/temp14.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) create mode 100755 t/temp14.sh
t/temp14.sh new file +63 -0
@@ -0,0 +1,63 @@ +#!/bin/sh + +test_description='undetected renames cause merge problems' + +. ./test-lib.sh + +test_expect_success 'setup undetected rename causing conflict in merge' ' + printf "1\n2\n3\n4\n5\n" >a && + echo foo >b && + git add a b && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a c && + echo "Completely different content" >a && + git add a && + git commit -m B && + + git checkout -b C A && + echo 6 >>a && + git add a && + git commit -m C +' + +test_expect_success 'undetected rename causes conflict' ' + git checkout -q C^0 && + git merge -s recursive B^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test 6 -eq $(wc -l < c) && + test $(git rev-parse HEAD:a) = $(git rev-parse B:a) && + test $(git rev-parse HEAD:b) = $(git rev-parse A:b) +' + +test_expect_success 'setup undetected rename causing missed merge conflict' ' + git reset --hard && + git clean -f && + + git checkout -b D A && + echo 7 >>a && + git add a && + git mv a c && + echo "Completely different content" >a && + git add a && + git commit -m D && + + git checkout -b E A && + git rm a && + echo "Completely different content" >>a && + git add a && + git commit -m E +' + +test_expect_success 'undetected rename causes missed conflict' ' + git checkout -q E^0 && + test_must_fail git merge -s recursive D^0 +' + +test_done
Signature · 1 line
1.7.4