package merge-fmt

Build not yet checked
  1. Overview
  2. Docs
Git mergetool leveraging code formatters

Install

dune-project
 Dependency

Authors

Maintainers

Sources

merge-fmt-0.5.1.tbz
sha256=748a3dafbcf057bfb62ec2339f0bac290385f6788d19d7271359ab347122dd94
sha512=f51cfe46327d7f886ad64856ef902eb201c2a40c636edec255233818ca616fbbba2a09950534ea3e992cd028a95f7f13aa6e43bbdcc2d4b7c1c0c879b3cb32b1

Description

merge-fmt is a small wrapper on top git commands to help resolve conflicts by leveraging code formatters.

Added to opam-repository:

README

Merge-fmt - git mergetool leveraging code formatters

build

WARNING: This tool is still experimental.

merge-fmt is a small wrapper on top git commands to help resolve conflicts by leveraging code formatters.

merge-fmt currently only knows about the following formatters:

  • ocamlformat for OCaml (.ml and .mli files).
  • refmt for Reason (.re and .rei files).
  • dune for dune (dune, dune-project and dune-workspace files).

They are looked up in the PATH. Use --ocamlformat, --refmt and --dune to run other ones.

Note that supporting new code formatters is trivial.

merge-fmt is tested on Linux, macOS and Windows.

Getting started

There are four ways to use merge-fmt.

Standalone

Just call merge-fmt while there are unresolved conflicts. merge-fmt will try resolve conflicts automatically.

It considers all the conflicted files of the repository, whatever the current directory is. The files it resolves are added to the index with git add. Files with conflicts left, and files without a formatter, are reported and left for you to resolve.

merge-fmt exits with 0 when no conflict is left in the repository, and with 1 otherwise.

As a Git mergetool

merge-fmt can act as a git mergetool. merge-fmt setup-mergetool prints the commands that configure the current git repository. Run them, or let merge-fmt do it with merge-fmt setup-mergetool --update.

$ merge-fmt setup-mergetool
git config --local mergetool.mergefmt.cmd 'merge-fmt mergetool --base="$BASE" --current="$LOCAL" --other="$REMOTE" -o "$MERGED" --name="$MERGED"'
git config --local mergetool.mergefmt.trustExitCode true

Then, use git mergetool to resolve conflicts with

git mergetool -t mergefmt

This command changed in merge-fmt 0.5.1: run merge-fmt setup-mergetool --update again in the repositories configured with an older version, where dune files are not formatted.

As a git merge driver

merge-fmt can act as a git merge driver. Configure the current git repository to use merge-fmt as the default merge driver with merge-fmt setup-merge --update, or by running the commands it prints.

$ merge-fmt setup-merge
git config --local merge.mergefmt.name 'merge-fmt driver'
git config --local merge.mergefmt.driver 'merge-fmt mergetool --base=%O --current=%A --other=%B -o %A --name=%P'
git config --local merge.tool 'mergefmt'
git config --local merge.default 'mergefmt'

As a Jujutsu merge tool

merge-fmt can act as a jujutsu merge tool. This requires jj 0.33 or later.

merge-fmt setup-jj-mergetool prints the commands that configure the current jj repository. Run them, or let merge-fmt do it with merge-fmt setup-jj-mergetool --update.

$ merge-fmt setup-jj-mergetool
jj config set --repo merge-tools.merge-fmt.program '"merge-fmt"'
jj config set --repo merge-tools.merge-fmt.merge-args '["mergetool", "--base=$base", "--current=$left", "--other=$right", "-o", "$output", "--name=$path", "--diff3"]'
jj config set --repo merge-tools.merge-fmt.merge-conflict-exit-codes '[1]'

Then, use jj resolve to resolve conflicts with

jj resolve --tool merge-fmt

Conflicts that are still there once the files are formatted are left for you to resolve.

When a file cannot be formatted

As a merge tool or a merge driver, when the formatter fails on one of the versions of a file, because of a syntax error for instance, merge-fmt says so and merges the versions as they are. It exits with 0 when the merge succeeds, and with 1 when the result has conflicts.

Install

$ opam install merge-fmt

The development version can be installed with

$ opam pin add merge-fmt https://github.com/hhugo/merge-fmt.git

Dependencies (5)

  1. stdio
  2. base
  3. cmdliner >= "1.1.0"
  4. ocaml >= "4.14"
  5. dune >= "3.15"

Dev Dependencies (4)

  1. odoc with-doc
  2. ocamlformat = "0.29.0" & with-test
  3. conf-diffutils with-test
  4. ppx_devtools-expect with-test

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building merge-fmt with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

This version is not in the latest run; the versions below are.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.4 good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure