Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve conflict resolution #627

Closed
wants to merge 6 commits into from
Closed

Conversation

tguillemot
Copy link

@tguillemot tguillemot commented Mar 27, 2022

I propose this work to solve #613: it replaces the merging approach using the rej files during an update by a two-way merge.

This PR is a based on the work of #407 with several differences:

  • using two-way merge instead of three-way merge
  • update the documentation to tell about how the conflict works and add an example of the check-merge-conflict pre-commit hook
  • update the existing tests

Why two-way instead of three : IMHO, I think the majority of the git users are used to the two-way merge instead of the three-way. I can be easily convince to change this behaviour. Maybe we can add an option to let the user choose what he wants.

I still have some remaining questions :

  1. How do we manage the retro compatibility ? The best way would be to add an option to keep the previous behaviour with warning to inform that it will be removed later.
  2. What can we do with the overwrite option ?

Thanks in advance for your help and time.

@yajo yajo linked an issue Mar 27, 2022 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Mar 27, 2022

Codecov Report

Merging #627 (5b1a817) into master (e983140) will decrease coverage by 0.23%.
The diff coverage is 90.19%.

@@            Coverage Diff             @@
##           master     #627      +/-   ##
==========================================
- Coverage   96.39%   96.16%   -0.24%     
==========================================
  Files          41       41              
  Lines        2722     2736      +14     
==========================================
+ Hits         2624     2631       +7     
- Misses         98      105       +7     
Flag Coverage Δ
unittests 96.16% <90.19%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tests/test_output.py 100.00% <ø> (ø)
copier/main.py 93.63% <89.13%> (-0.36%) ⬇️
tests/test_subdirectory.py 100.00% <100.00%> (ø)
tests/test_updatediff.py 100.00% <100.00%> (ø)
tests/conftest.py 84.61% <0.00%> (-7.70%) ⬇️
copier/tools.py 88.09% <0.00%> (-4.77%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e983140...5b1a817. Read the comment docs.

Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add co-autorship info with the author of #407 to credit him?

rev: v4.0.1
hooks:
- id: check-merge-conflict
args: [--assume-in-merge]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines have wrong indentation and are not valid yaml. Can you fix that please?

@yajo
Copy link
Member

yajo commented Mar 27, 2022 via email

Thierry and others added 2 commits March 28, 2022 19:08
Co-authored-by: Oleh Prypin <oprypin@users.noreply.github.com>
@yajo
Copy link
Member

yajo commented Mar 28, 2022

BTW have you seen #562? It displays the diff interactively to accept or reject before continuing.

@tguillemot
Copy link
Author

Please can you add co-autorship info with the author of #407 to credit him?

Of course. It's done.

I'd appreciate it if you could explain it and any solutions you may have thought

You're perfectly right, sorry for that.
In the current behaviour of copier the --overwrite option overwrite the files that already exist without asking. With the new behaviour we do not to overwrite things in the "old way", but it still make sense to give an option to the user to accept automatically merge upstream (a kind of git checkout --theirs). IMHO, I prefer to remove the overwrite option and let the user manage the conflict as he wants on his side.

@tguillemot
Copy link
Author

BTW have you seen #562? It displays the diff interactively to accept or reject before continuing.

Indeed I missed that PR.

# Remove the file if it was already removed in the project
if not output and "modified" not in subfile_names:
try:
dest_path.unlink()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you fixing #461 too? 😍

@yajo
Copy link
Member

yajo commented Mar 29, 2022

I'll have to review more in depth, because the part you're modifying is one of the most important in copier. Just be patient please.

@tguillemot
Copy link
Author

@yajo Don't worry for the time, I understand perfectly :)

And I have to find a way to fix windows problems first.

Fixing mistake with python version
subfile_kind = os.devnull
subfile_names.append(subfile_kind)

with local.cwd(merge_dst_temp):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is the perfect spot to check if the file has changed and show a brief diff to the user (difflib.unified_diff(old_upstream, new_upstream))

@barrywhart
Copy link
Contributor

@yajo, @tguillemot: What's the status of this PR? If you don't have time to work on it, I can work on it.

I personally prefer 3-way merge: That's the behavior that gives you conflict markers, right? E.g.

<<<<<<< HEAD
foo
=======
bar
>>>>>>> cb1abc6bd98cfc84317f8aa95a7662815417802d

@yajo: You mentioned needing to review it carefully due to the risk of breaking copier. Should we consider making the behavior configurable?

  • Old way: .rej files
  • New way: Inline conflict markers
  • Potentially: New way 2: 2-way merge

@yajo
Copy link
Member

yajo commented Sep 24, 2022

Continuing in #807, which has no conflicts

@yajo yajo closed this Sep 24, 2022
yajo added a commit that referenced this pull request Nov 14, 2022
Fixes #613 

Based on #627, but:

* Supports both old (`.rej` files) and new (inline markers) conflict behavior

* Update a test to test both rej and inline conflict resolution

* Update some tests to explicitly specify "rej" conflict mode

* Add documentation for the two conflict modes

* keeping only 3-way merge

Co-authored-by: Oleh Prypin <oprypin@users.noreply.github.com>
Co-authored-by:
Thierry Guillemot <tguillemot@users.noreply.github.com>
Co-authored-by: Barry Hart <barry.hart@zoro.com>
Co-authored-by: Jairo Llopis <yajo.sk8@gmail.com>
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve conflict resolution
5 participants