-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
Merge conflicts on update disappear in git mergetool
or some IDEs
#1833
Comments
Do you mean that there isn't any conflict marker in the file anymore? If that's the case, I believe we have fixed this in #1813. About the file hashes:
It's possible that I took a shortcut. I'm not particularly knowledgeable of Git's internals, so I did the easy thing and just updated the index with all three staging modes using the same hash. Should we instead hash three different temporary files, one for each possible conflict resolution? |
Seeing that you point at a commit from yesterday as your Copier version, I worry the fix I mention has no effect on your issue 😅 Waiting for your confirmation. However I'm not sure to fully understand your issue yet. |
Yeah, rereading it was very unclear. The conflict markers are there in the file, but I've tried to make a clear reproduction using a test template where only one file ( # In a new directory, copy v1.0 of the template.
git init
copier copy --vcs-ref 1.0 https://github.com/borispf/test-template.git .
git add .
git commit -m v1
# Make a conflicting change.
echo version 2 > version.txt
git add .
git commit -m v2
# Then do a template update to generate the conflict
copier update Then some relevant output: # version.txt correctly shown as both modified.
$ git status
On branch main
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: version.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .copier-answers.yml
no changes added to commit (use "git add" and/or "git commit -a")
# version.txt has the expected conflict markers.
$ cat version.txt
<<<<<<< before updating
version 2
=======
version 1.1
>>>>>>> after updating
# ls-files shows that version.txt has different versions, but the they all have the same sha1?
$ git ls-files --stage
100644 10f1cf1b6e306695e7572a28faa7077bcadbfcd1 0 .copier-answers.yml
100644 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a 1 version.txt
100644 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a 2 version.txt
100644 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a 3 version.txt
# seems like git thinks all there files are just the v2.
$ git cat-file -p 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
version 2 And now in VSCode's merge editor you can see the issue: Click on Merge Editor bottom right All of the changes or merge conflicts are gone. Similar in vimdiff, all of the source files are the same, at least the result still shows the merge conflict: This is the repo zipped up if it helps: test.zip. I hope that's a little clearer. |
That's much clearer, thanks. I never use VSCode's "Merge Editor", only the "Source Control" tab. Not sure if that's fixable. We could try and set the right hashes for each mode, but that doesn't mean the files would be there for merge tools to see them? My Git-fu is lacking here 🤷 |
Confirming the issue in a different way: after a
Yet, whether I run Coming back to this:
...and looking at the code, the 3-way merge is done like this: git(
"merge-file",
"-L",
"before updating",
"-L",
"last update",
"-L",
"after updating",
fname,
Path(old_copy) / fname,
Path(new_copy) / fname,
retcode=None,
) ...so we do have files on the disk, and wouldn't need to re-create temporary ones. Maybe I just have to use these files ( EDIT: the hashes are blob ids, not file hashes. Not sure how to retrieve them from Git, if they even exist. Posted this SO question: https://stackoverflow.com/questions/79309642/git-checkout-ours-theirs-after-git-merge-files-with-external-files. |
Got a fantastic answer on SO again, sending a PR 🙂 |
Describe the problem
When running
copier update
with inline conflict markers, if there is a conflict the file in the worktree will have conflict markers as expected,git status
will report the file asboth modified
, but if you open the file withgit mergetool
, or the built-in merge editors in VS Code or PyCharm the conflict has disappeared and only the local change is shown form all three-files in the three-way merge.I believe the problem was introduced in #1396, and is related to the index having the same version of the file three times.
Template
The problem occurred with a work-internal template that I unfortunately cannot share, but I believe I have recreated the issue in the copier test suite.
To Reproduce
git checkout 6bba7614a32a4023f11d8170dd97232b3006d5be
tests/test_updatediff.py::test_conflicted_files_are_marked_unmerged
, appending:PYTEST_XDIST_AUTO_NUM_WORKERS=0 poetry run pytest -s 'tests/test_updatediff.py::test_conflicted_files_are_marked_unmerged[README.md]'
Logs
Expected behavior
All three versions of README.md in
git ls-files --stage
should have different git hashes.Screenshots/screencasts/logs
No response
Operating system
macOS
Operating system distribution and version
Sonoma 14.6.1 (23G93)
Copier version
6bba761
Python version
CPython 3.12.7
Installation method
local build
Additional context
No response
The text was updated successfully, but these errors were encountered: