Mix Git dependency with shallow clone

,

Hi all,

I would like to gather some feedback before a more intentional proposal to add a new :depth option when specifying a Git dependency on mix.exs.

I noticed that Mix Git dependencies have several smart options, including :ref and :sparse, but there is no way to tell mix to make shallow clones for use cases where the full repository history is not needed.

Shallow clones have the potential to reduce the space in disk for dependencies installed from Git/GitHub, as well as save time on deployments/CI by downloading less data.

One use case for me is to depend on a tagged version of Heroicons by pulling in as little data as possible (see Vendored heroicons take up considerable space on new projects · Issue #5622 · phoenixframework/phoenix · GitHub).

Would your workflows benefit from such new :depth option? Would you prefer having something else instead?


Notes

  • Impact on existing eco-system: I think minimal. The change would add one more line in the Mix documentation linked above, code changes to pass the --depth flag to git (though I’m not familiar with how Git integration is actually implemented yet). The option can be safely ignored by most people, and appreciated by those who need it.
  • Impact on learning: No one needs to learn about this until they need to use it (and then they might bring their Git knowledge from elsewhere anyway).
  • I have not found similar suggestions in the past. I found that the most recent addition was :subdir in Elixir 1.13.

If the community finds this useful and a proposal would be accepted, I would like to work on it and submit a PR.

3 Likes

For (perhaps my own) reference, this is the PR that added :subdir back in July 2021: mix deps: Add :subdir option to git deps by wojtekmach · Pull Request #11125 · elixir-lang/elixir · GitHub

I would accept a PR for --depth but we need to be careful with what happens when you initially clone a repo with --depth 1 and then you change it to point to another reference. Our code needs to be smart enough to know that it needs to fetch something more recent.

2 Likes