How to patch a git dependency in rust with same location but different branch


At my current employer, we are developing multiple internal libraries in Rust. They are hosted in a git based code hosting. Here is how we can specify them from a different repository.

Sometimes we want to modify a repository (we will call it “Start”) that happens to be one of the lowest dependencies in the tree. And we want to test that a specific repository (we will call it “End”) that uses the “Start” dependency indirectly still works. For instance, we could have the following chain of dependencies: “End” -> “A” -> “B” -> “C” -> “Start”, where ”->” represents a dependency.

Rust allows to override dependencies, but it does not work in all situations. For instance, it does not allow patching a git repository using a different branch of the same repository. The fix is simple but easy to misconfigure. I have problems configuring it every time I need to do it.

[patch.'https://github.com/company/Start']
start = { git = "https://www.github.com/company//Start.git", branch = "new-feature" }

There are two important details there.

  • The patch url does not include the trailing “.git”
  • The url in the second line contains ”//” before “Start.git”

Without these two things, you will end with the following error:

Caused by:
  patch for `start` in `https://github.com/company/Start` points to the same source, but patches must point
  to different sources