Skip to content

Add scripts/nixfmt-mergetool#277

Closed
oxij wants to merge 1 commit intoNixOS:masterfrom
oxij:mergetool
Closed

Add scripts/nixfmt-mergetool#277
oxij wants to merge 1 commit intoNixOS:masterfrom
oxij:mergetool

Conversation

@oxij
Copy link
Member

@oxij oxij commented Jan 23, 2025

The script is self-documenting.

IMHO, this script should also be added to the output of nixfmt-rfc-style of Nixpkgs. Otherwise, after recent treewide changes, things became impossible to merge manually.

@github-actions
Copy link

github-actions bot commented Jan 23, 2025

Nixpkgs diff

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

Neat, I didn't know about git mergetool! While this way of merging isn't fool-proof against syntactic errors, it is quicker than the auto-rebase script, and there's no problem with having both, so I say let's have this. Will need some work to integrate into the build, but we can do this in follow-up PRs.

For reference, here's an example of a syntactic error that can be introduced. Consider this file:

{
  foo

# , bar
}:
null

Formatting this on one branch turns it into

{
  foo,

# , bar
}:
null

But if on another branch the extra argument gets uncommented:

{
  foo

  , bar
}:
null

You'll end up with this invalid merge result (no merge conflict):

{
  foo,

  , bar
}:
null

This is an easily catchable syntactic error though. I can't imagine such a failure changing semantics, but would love to be proven wrong.

Comment on lines +2 to +5
# Copyright (c) 2025 Jan Malakhovski <[email protected]>
#
# This file can be redistributed under the terms of Unlicense
# <https://unlicense.org> license.
Copy link
Member

Choose a reason for hiding this comment

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

The only worry I have is the re-introduction of separately licensed files, which we moved away from in the past: #171. Would you be okay with you to re-license it under the MPL-2.0 license and assign copyright to the generic "Nixfmt contributors" as defined in

nixfmt/.reuse/dep5

Lines 3 to 6 in e825e95

Files: *
Copyright: 2019-2022 Serokell <[email protected]>
2019-2024 Nixfmt Contributors
License: MPL-2.0
?

Suggested change
# Copyright (c) 2025 Jan Malakhovski <[email protected]>
#
# This file can be redistributed under the terms of Unlicense
# <https://unlicense.org> license.

infinisil added a commit that referenced this pull request Feb 17, 2025
Inspired by oxij's #277, but
implemented in Haskell, therefore faster (less process spawning) and
trivially integrated into the build and distribution.
@infinisil infinisil mentioned this pull request Feb 17, 2025
2 tasks
@infinisil
Copy link
Member

Because it's a bit tedious to distribute a shell script along with the build, I made a PR to implement this directly in the Haskell codebase: #283. This also benefits from improved speed, because three less processes need to be spawned.

@oxij
Copy link
Member Author

oxij commented Feb 18, 2025 via email

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/formatting-team-meeting-2025-02-18/60511/1

@infinisil
Copy link
Member

Also just opened numtide/treefmt#523, because this functionality would be useful for all formatters :)

infinisil added a commit that referenced this pull request Feb 21, 2025
Makes resolving formatting-related conflicts easier.

Idea and docs are from @oxij's #277.
Code and tests are from @infinisil.

By implementing it in Haskell, it's faster (less process spawning)
and trivially integrated into build and distribution.

Co-Authored-By: Jan Malakhovski <[email protected]>
infinisil added a commit that referenced this pull request Feb 24, 2025
Makes resolving formatting-related conflicts easier.

Idea and docs are from @oxij's #277.
Code and tests are from @infinisil.

By implementing it in Haskell, it's faster (less process spawning)
and trivially integrated into build and distribution.

Co-Authored-By: Jan Malakhovski <[email protected]>
@infinisil
Copy link
Member

Done in #283

@infinisil infinisil closed this Mar 3, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in Nix formatting Mar 3, 2025
nikolaik pushed a commit to nikolaik/nixfmt that referenced this pull request Jun 8, 2025
Makes resolving formatting-related conflicts easier.

Idea and docs are from @oxij's NixOS#277.
Code and tests are from @infinisil.

By implementing it in Haskell, it's faster (less process spawning)
and trivially integrated into build and distribution.

Co-Authored-By: Jan Malakhovski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants