Create a patch/pull request for an OCaml lib with opam

What is the “workflow” when you want to create/test a patch for a library that is installed via opam. Note: The sources of the library are on Github.

After reading the documentation of opam, It looks like I just should do :

  • clone the source of the lib localy
  • create a branch
  • use opam pin package local_clone in order to tell opam to use the local sources for the installation of package
  • use opam install package in order to install the modified version
  • test the modifications
  • send a Pull Request
  • use opam pin remove package in order to let opam use the normal sources to install pacakge.

Is it the good way to do it ?

1 Like

That’s pretty much right. If you are not testing packages that depend on the one you are editing, then you don’t need to pin and install. Also, opam pin add package local_clone.

If you need the change for yourself, you often end up with these pins for a while, until the PR is merged, and then the change is later released into OPAM.

Is there a command to list the pins ? (thanks for your help)

Yep, I believe opam pin list will do it. The pin list is different for each OPAM switch.

1 Like

You can streamline this a bit more by automating the fetching of the sources:

$ opam source thepkg --dev
# this fetches the development version of the source code
$ opam pin add thepkg thepkg/
# pin and install it
$ cd thepkg && hack-hack-hack
1 Like

opam source also has a --pin flag, so it can be made even shorter:

$ opam soutce thepkg --dev --pin

This will create a local thepkg directory containing the source, and build the package from there. You can then edit the source and iterate with opam upgrade thepkg (or even opam upgrade . from the source directory, with opam 2.0).

3 Likes