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

chore: use npm as a merge tool #370

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boneskull
Copy link
Collaborator

So package-lock.json gets conflicted often enough and this can be a pain.

The following bit in a .gitattributes is used in the appium monorepo:

package-lock.json merge=binary

This is fine, except when confronted with a conflict, Git will just punt; I suppose that's better than the default alternative--which is a poor text merge indeed.

But, I know that the way to resolve these conflicts is to run npm install. I thought; why not just do that?

So this does that -- though it requires a manual step for security reasons.

When Git detects a conflict in package-lock.json, it will run the npm merge tool--which just runs npm install. If npm install exits with a 0 error code and package-lock.json was modified, Git will mark package-lock.json as resolved.

If there's also a conflict in package.json this will not work, because npm install can't run if your package.json is in a conflicted state.

To enable this, the developer has to run

git config --local include.path ../.gitconfig

This modifies .git/config and tells it to include .gitconfig (added). Git will otherwise not recognize the .gitconfig file and the auto-merge of package-lock.json will fail, and you'll have to run npm install yourself as before.

Please try this and see if it's helpful. It might not be.

@boneskull boneskull requested a review from jlipps April 10, 2023 22:32
@boneskull boneskull self-assigned this Apr 10, 2023
@boneskull boneskull force-pushed the boneskull/experimental-git-config branch from 093a828 to d513583 Compare April 10, 2023 22:35
@boneskull
Copy link
Collaborator Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@boneskull boneskull force-pushed the boneskull/experimental-git-config branch 3 times, most recently from ff118d3 to 78db161 Compare April 11, 2023 17:19
Copy link
Collaborator

@jlipps jlipps left a comment

Choose a reason for hiding this comment

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

yeah this is a good idea for an annoying problem!

@boneskull boneskull force-pushed the boneskull/experimental-git-config branch 2 times, most recently from f798884 to 88da47b Compare April 12, 2023 17:31
@boneskull
Copy link
Collaborator Author

@jlipps Did you try it?

@jlipps
Copy link
Collaborator

jlipps commented Apr 19, 2023

not yet!

@boneskull boneskull force-pushed the boneskull/experimental-git-config branch from 88da47b to 2aca82c Compare April 20, 2023 18:43
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.

None yet

2 participants