Skip to content

How to resolve formatting-related conflicts #395247

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

Open
infinisil opened this issue Apr 1, 2025 · 4 comments
Open

How to resolve formatting-related conflicts #395247

infinisil opened this issue Apr 1, 2025 · 4 comments

Comments

@infinisil
Copy link
Member

infinisil commented Apr 1, 2025

With #380990 (and #395018 on the release branch), there will be a lot of merge conflicts related to formatting (see the announcement for more context). Here are the options for resolving them more easily

Method 1: Auto-rebase script

You can use the new auto-rebase script. This takes some time to run (especially if you have a lot of commits in your PR), but should take care of rebasing the current branch while automatically resolving any merge conflicts caused by the full Nixpkgs reformat:

git fetch upstream
maintainers/scripts/auto-rebase/run.sh upstream/master

Method 2: git mergetool

Warning

This method has a bug (see NixOS/nixfmt#291 for the fix, though it will take some time for it to be propagated) that can affect merge correctness. As such, it is not recommended right now. If you use it regardless, make sure to double-check the result for correctness.

Instructions

Nixfmt newly provides a mode usable by git mergetool that is faster and more general than the above, and allows resolving almost all formatting-related conflicts automatically.
There's more extensive docs, but the most basic way to use it is as follows:

# Run these once:
git config mergetool.nixfmt.cmd 'nixfmt --mergetool "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config mergetool.nixfmt.trustExitCode true

# Run these to rebase:
git rebase master
git mergetool -t nixfmt .
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-formatting-team-full-nixpkgs-reformat/61867/3

@RossComputerGuy
Copy link
Member

RossComputerGuy commented Apr 2, 2025

Might be good to mention that the cloned nixpkgs's master branch should be using an up-to-date rev to prevent rebasing issues.

I kept on running into conflict issues and didn't realize that I had to update my clone's master branch.

@RossComputerGuy
Copy link
Member

RossComputerGuy commented Apr 5, 2025

I run into this a bunch:

Auto-rebasing commit 374e6bcc403e02a35e07b650463c01a52b13a7c8 with command 'nix-shell --run treefmt'
Rebasing on top of the previous commit, might need to manually resolve conflicts
Successfully rebased and updated refs/heads/feat/toolchain-attrs.
Reapplying the commit on each commit of our branch
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f

rm -rf .git/refs/original fixes the issue but feels wrong

@nobodyinperson
Copy link
Contributor

I have made good experiences with mergiraf. When nothing else worked to resolve merge conflicts (including formatting-related) in a PR here, mergiraf resolved everything in the background without breaking a sweat. Maybe worth mentioning here.

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

No branches or pull requests

4 participants