Some small fixes to merge-recursive and tests
cover Some small fixes to merge-recursive and tests
These three patches were the first three from en/rename-directory-detection[1], but as Stefan suggested[2], I'm submitting them separately as they are independent fixes.
Change from PATCHv5-rename-directory-detection:
* Split from the rest of the series.
* Added Stefan's Reviewed-By.
[1] https://public-inbox.org/git/[email protected]/
[2] https://public-inbox.org/git/CAGZ79kapuEKLO4RUUPVS6_-aeBERDhjpBAtmK=gycT8GaK2bFg@mail.gmail.com/
Elijah Newren (3):
Tighten and correct a few testcases for merging and cherry-picking
merge-recursive: fix logic ordering issue
merge-recursive: add explanation for src_entry and dst_entry
merge-recursive.c | 21 ++++++++++++++++++++- t/t3501-revert-cherry-pick.sh | 7 +++++-- t/t7607-merge-overwrite.sh | 5 ++++- 3 files changed, 29 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.2
PATCH 1/3 Tighten and correct a few testcases for merging and cherry-picking
t3501 had a testcase originally added in 05f2dfb965 (cherry-pick:
demonstrate a segmentation fault, 2016-11-26) to ensure cherry-pick wouldn't segfault when working with a dirty file involved in a rename. While the segfault was fixed, there was another problem this test
demonstrated: namely, that git would overwrite a dirty file involved in a rename. Further, the test encoded a "successful merge" and overwriting of this file as correct behavior. Modify the test so that it would still catch the segfault, but to require the correct behavior. Mark it as test_expect_failure for now too, since this second bug is not yet fixed.
t7607 had a test added in 30fd3a5425 (merge overwrites unstaged changes in renamed file, 2012-04-15) specific to looking for a merge overwriting a dirty file involved in a rename, but it too actually encoded what I would term incorrect behavior: it expected the merge to succeed. Fix that, and add a few more checks to make sure that the merge really does produce the expected results.
--- t/t3501-revert-cherry-pick.sh | 7 +++++-- t/t7607-merge-overwrite.sh | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-)
t/t3501-revert-cherry-pick.sh +5 -2
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' ' test_cmp expect actual ' -test_expect_success 'cherry-pick works with dirty renamed file' ' +test_expect_failure 'cherry-pick works with dirty renamed file' ' test_commit to-rename && git checkout -b unrelated && test_commit unrelated &&
@@ -150,7 +150,10 @@ test_expect_success 'cherry-pick works with dirty renamed file' ' test_tick && git commit -m renamed && echo modified >renamed && - git cherry-pick refs/heads/unrelated + test_must_fail git cherry-pick refs/heads/unrelated >out && + test_i18ngrep "Refusing to lose dirty file at renamed" out && + test $(git rev-parse :0:renamed) = $(git rev-parse HEAD^:to-rename.t) && + grep -q "^modified$" renamed ' test_done
t/t7607-merge-overwrite.sh +4 -1
@@ -97,7 +97,10 @@ test_expect_failure 'will not overwrite unstaged changes in renamed file' ' git mv c1.c other.c && git commit -m rename && cp important other.c && - git merge c1a && + test_must_fail git merge c1a >out && + test_i18ngrep "Refusing to lose dirty file at other.c" out && + test_path_is_file other.c~HEAD && + test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) && test_cmp important other.c '
Signature · 1 line
2.14.2
Re: [PATCH 1/3] Tighten and correct a few testcases for merging and cherry-picking
Hi Elijah,
Quoted 8 lines · Elijah Newren
t3501 had a testcase originally added in
05f2dfb965(cherry-pick:
demonstrate a segmentation fault, 2016-11-26) to ensure cherry-pick wouldn't segfault when working with a dirty file involved in a rename.While the segfault was fixed, there was another problem this test
demonstrated: namely, that git would overwrite a dirty file involved in a rename. Further, the test encoded a "successful merge" and overwriting of this file as correct behavior.
Whoops. Sorry about that. Thanks for the patch, looks obviously good (I haven't read 3/3 yet, but figure that the error message stems from the changes introduced in that patch).
Ciao,
Dscho
PATCH 2/3 merge-recursive: fix logic ordering issue
In reply to Elijah Newrenmerge_trees() did a variety of work, including:
* Calling get_unmerged() to get unmerged entries
* Calling record_df_conflict_files() with all unmerged entries to do some work to ensure we could handle D/F conflicts correctly
* Calling get_renames() to check for renames.
An easily overlooked issue is that get_renames() can create more unmerged entries and add them to the list, which have the possibility of being involved in D/F conflicts. So the call to record_df_conflict_files() should really be moved after all the rename detection. I didn't come up with any testcases demonstrating any bugs with the old ordering, but I suspect there were some for both normal renames and for directory renames. Fix the ordering.
--- merge-recursive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
merge-recursive.c +1 -1
@@ -1982,10 +1982,10 @@ int merge_trees(struct merge_options *o,get_files_dirs (o, merge); entries =get_unmerged (); -record_df_conflict_files (o, entries); re_head =get_renames (o, head, common, head, merge, entries); re_merge =get_renames (o, merge, common, head, merge, entries); clean =process_renames (o, re_head, re_merge); +record_df_conflict_files (o, entries);if (clean <0 ) goto cleanup;for (i = entries->nr-1 ;0 <= i; i--) {
Signature · 1 line
2.14.2
Re: [PATCH 2/3] merge-recursive: fix logic ordering issue
Hi Elijah,
Quoted 11 lines · Elijah Newren
merge_trees()did a variety of work, including:
* Callingget_unmerged()to get unmerged entries
* Callingrecord_df_conflict_files()with all unmerged entries to do some work to ensure we could handle D/F conflicts correctly
* Callingget_renames()to check for renames.An easily overlooked issue is that
get_renames()can create more unmerged entries and add them to the list, which have the possibility of being involved in D/F conflicts. So the call torecord_df_conflict_files()should really be moved after all the rename detection.
I cannot actually see how the *current* rename detection would result in D/F conflicts, as it is really only about detecting the renames, the conflicts should have happened earlier.
But I could imagine that your "detect directory renames" patch series changes this behavior.
In any case, the reordering does not hurt.
Ciao,
Dscho
PATCH 3/3 merge-recursive: add explanation for src_entry and dst_entry
In reply to Elijah NewrenIf I have to walk through the debugger and inspect the values found in here in order to figure out their meaning, despite having known these things inside and out some years back, then they probably need a comment for the casual reader to explain their purpose.
--- merge-recursive.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
merge-recursive.c +19 -0
@@ -513,6 +513,25 @@ static void record_df_conflict_files(struct merge_options *o,struct rename {struct diff_filepair *pair; +/* +* Purpose of src_entry and dst_entry: +* +* If 'before' is renamed to 'after' then src_entry will contain +* the versions of 'before' from the merge_base, HEAD, and MERGE in +* stages 1, 2, and 3; dst_entry will contain the respective +* versions of 'after' in corresponding locations. Thus, we have a +* total of six modes and oids, though some will be null. (Stage 0 +* is ignored; we're interested in handling conflicts.) +* +* Since we don't turn on break-rewrites by default, neither +* src_entry nor dst_entry can have all three of their stages have +* non-null oids, meaning at most four of the six will be non-null. +* Also, since this is a rename, both src_entry and dst_entry will +* have at least one non-null oid, meaning at least two will be +* non-null. Of the six oids, a typical rename will have three be +* non-null. Only two implies a rename/delete, and four implies a +* rename/add. +*/ struct stage_data *src_entry;struct stage_data *dst_entry;unsigned processed:1 ;
Signature · 1 line
2.14.2
Re: [PATCH 3/3] merge-recursive: add explanation for src_entry and dst_entry
Hi Elijah,
Quoted 4 lines · Elijah Newren
If I have to walk through the debugger and inspect the values found in here in order to figure out their meaning, despite having known these things inside and out some years back, then they probably need a comment for the casual reader to explain their purpose.
Makes sense.
Thanks,
Dscho