Skip to content

nix: add merge-driver for treefmt - #5224

Open
wolfgangwalther wants to merge 1 commit into
PostgREST:mainfrom
wolfgangwalther:merge-driver
Open

nix: add merge-driver for treefmt#5224
wolfgangwalther wants to merge 1 commit into
PostgREST:mainfrom
wolfgangwalther:merge-driver

Conversation

@wolfgangwalther

Copy link
Copy Markdown
Member

This adds a custom merge-driver and sets our nix-shell up to automatically activate it when entering the shell. This will allow us to transparently rebase through formatter-related changes without conflicts.

I tested this with a branch changing the default nix formatter to nixfmt (which is something that we should do as well - the one we're currently using is archived since 2024!).

Let's assume this script is merged and we then merge a formatter change such as nixfmt or fourmolu to main. Usage is then as simple as:

  • Enter nix-shell on main. The merge-driver is activated via git config.
  • Switch to the branch that needs to be rebased... and rebase it.
  • Formatting-related merge conflicts will be resolved automatically. Other conflicts can of course still appear.
  • New code is also not necessarily formatted immediately, so running treefmt still makes sense.

The important part is entering nix-shell on the branch that already has the formatter changes in nix/treefmt.nix. When entering the shell on the branch that needs rebasing, it would enable the old configuration, so would format everything the wrong way.

This adds a custom merge-driver and sets our nix-shell up to
automatically activate it when entering the shell. This will allow us to
transparently rebase through formatter-related changes without
conflicts.
@steve-chavez

Copy link
Copy Markdown
Member

For reference about merge-driver: https://graphite.com/guides/git-merge-driver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants