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

Unexpected merge conflict when updating with nested object as argument in data file #1849

Closed
thor-matter opened this issue Nov 7, 2024 · 5 comments
Labels
bug triage Trying to make sure if this is valid or not

Comments

@thor-matter
Copy link

thor-matter commented Nov 7, 2024

Describe the problem

Thank for a great tool! I have been using Copier for a while now and I am very happy with it.

However, recently I get an unexpected merge conflict when applying an update with a nested object as an argument within a data file.

I have attached a basic template to reproduce the issue.

This may be related to the following Issue regarding hidden merge conflict details in tools. I am experiencing the same problem in pycharm git integration.

#1833

Template

template-basic.zip

To Reproduce

Steps to reproduce:

$ mkdir test-basic
$ cd test-basic
$ git init

$ copier copy ../template-basic . 
$ git add .
$ git commit -m "Initial commit"

$ copier update --data-file data.yaml 
$ git add .
$ git commit -m "Update items from data file"

$ copier update --data-file data.yaml 

$ git status
On branch master
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
	both modified:   document.md

no changes added to commit (use "git add" and/or "git commit -a")

$ git diff
diff --cc document.md
index a552bb2,a552bb2..0000000
--- a/document.md
+++ b/document.md

In addition, I get an unexpected merge conflict when changing the items in the data file.

$ sed -i 's/3/4/g' data.yaml
$ git add .
$ git commit -m "Change items in data file"

$ copier update --data-file data.yaml

$ git status
On branch master
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
	both modified:   document.md

no changes added to commit (use "git add" and/or "git commit -a")

$ git diff
diff --cc document.md
index a552bb2,a552bb2..0000000
--- a/document.md
+++ b/document.md
@@@ -7,6 -7,6 +7,10 @@@ Here are our items
      
          this: 2
      
++<<<<<<< before updating
          test: 3
++=======
++        test: 4
++>>>>>>> after updating

Logs

No response

Expected behavior

I would not expect any merge conflicts in the described conditions.

Screenshots/screencasts/logs

No response

Operating system

Linux

Operating system distribution and version

Ubuntu 22.04.5 LTS

Copier version

copier 9.4.1

Python version

3.12.2

Installation method

pipx+git

Additional context

No response

@thor-matter thor-matter added bug triage Trying to make sure if this is valid or not labels Nov 7, 2024
@pawamoy
Copy link
Contributor

pawamoy commented Nov 7, 2024

First issue might be fixed by #1813.

For the second issue, when Copier runs the update after you've modified data.yaml:

  • it regens a new project with this data file (test=4)
  • meaning document.md has test: 4 in it
  • it computes the diff between this fresh project and your current project: test: 4 -> test 3!
  • it updates the current project in-place: document.md now contains test: 4
  • but the computed diff says it must be test: 3!

I suppose that's how you get the merge conflict. And this behavior seems correct, although maybe not intuitive. IMO it stems from how data.yaml and document.md become de-synchronized when you update only data.yaml. Not sure if this is something Copier should support.

Also, maybe my analysis is wrong.

@thor-matter
Copy link
Author

thor-matter commented Nov 7, 2024

First issue might be fixed by #1813.

I'm running the latest version, so I don't think this resolved the issue I'm seeing.

For the second issue, when Copier runs the update after you've modified data.yaml:

  • it regens a new project with this data file (test=4)
  • meaning document.md has test: 4 in it
  • it computes the diff between this fresh project and your current project: test: 4 -> test 3!
  • it updates the current project in-place: document.md now contains test: 4
  • but the computed diff says it must be test: 3!

I suppose that's how you get the merge conflict. And this behavior seems correct, although maybe not intuitive. IMO it stems from how data.yaml and document.md become de-synchronized when you update only data.yaml. Not sure if this is something Copier should support.

Maybe I'm confused then. Is the data file not regarded as a kind of answer?

I did some testing where I would store the items provided from the data file in the answers file, and I did see different behavior, but still the confusion persists. It would make sense to me that changes in the data file would apply as an answer change.

To be clear, the file is marked with a conflict, when the template should simply update the value, as it does when changing an answer. Maybe it has something to do with the size of the data structure?

@pawamoy
Copy link
Contributor

pawamoy commented Nov 7, 2024

I'm running the latest version, so I don't think this resolved the issue I'm seeing.

The fix from #1813 was not released yet.

@thor-matter
Copy link
Author

I'm running the latest version, so I don't think this resolved the issue I'm seeing.

The fix from #1813 was not released yet.

Ah, my bad. I'll do some testing based on the master branch instead.

@thor-matter
Copy link
Author

I have tested master and can confirm that the merge bug has been fixed. It would be great to have it released.

The other bug is reported here #1833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Trying to make sure if this is valid or not
Projects
None yet
Development

No branches or pull requests

2 participants