‹ jan0sch.de

How to add a darcs pre record hook for scalafmt.

2022-06-21

VCS usually have hooks into which commands can be “plugged” to be executed automatically upon certain events and the great darcs is no exception.

Having your code checked for formatting guidelines before you record (commit) it is quite convenient and so let us implement a prerecord hook for darcs that instruments sbt to check you code style.

First you have to create the file _darcs/prefs/defaults if it not yet exists in your repository.

Within the aforementioned file you add the following line:

record prehook sbt "scalafmtCheckAll; IntegrationTest/scalafmtCheckAll"

Depending on your setup you may skip the IntegrationTest/scalafmtCheckAll part.

From now on darcs will execute that command whenever you want to record your changes. :-)