Search code examples
gitelixirelixir-mixsemantic-versioning

How to use Git tags with semantic versioning in mix.exs?


Background

We have a private repository in git that uses tags. In our mix.exs we have the following:

  defp deps do
    [
      { :plug,    "~> 1.0"  },
      { :my_repo, git: "git@github.com:my_company/my_repo.git", tag: "1.0.0"  }
    ]
  end

Now if I only want version 1.0.0 from :my_repo that's fine. However what happens if I want any version compatible with 1.0.0? The original documentation doesn't seem to have an options flag for this:

https://hexdocs.pm/mix/Mix.Tasks.Deps.html

Problem

This is what is happening in { :plug, "~> 1.0" },. Here I say "give any 1.X version compatible with this one".

I want the same thing for git repos. After checking the git docs, I know this is possible using the -l command:

https://git-scm.com/book/en/v2/Git-Basics-Tagging

git tag -l "1.8.5*" would return all versions compatible with 1.8.5.

Questions

  1. Is there a way to pass the -l option to the mix.exs deps function?
  2. If not, what other options do I have?

Solution

  • Is there a way to pass the -l option to the mix.exs deps function?

    Not that I am aware of.

    If not, what other options do I have?

    I would either propose a PR to mix core or just introduce your own Mix.SCM implementation, along with existing git and path, that would be an exact copy-paste from Mix.SCM.Git but allowing / hardcoding -l option.