Skip to content

Conversation

@jeffreylo
Copy link
Contributor

@jeffreylo jeffreylo commented Dec 17, 2025

When GIT_TRACE=1 is set in the env, mix deps.get fails with an unexpected FunctionClauseError due to git --version's output including trace output from git itself:

λ GIT_TRACE=1 mix deps.get
* Getting bar (git@github.com:foo/bar.git - main)
22:17:06.786357 git.c:476               trace: built-in: git init --quiet
22:17:06.798692 git.c:476               trace: built-in: git remote add origin git@github.com:foo/bar.git
22:17:06.804333 git.c:476               trace: built-in: git config remote.origin.url git@github.com:foo/bar.git
** (FunctionClauseError) no function clause matching in Mix.SCM.Git.parse_version/1

    The following arguments were given to Mix.SCM.Git.parse_version/1:

        # 1
        "22:17:06.809548 git.c:476               trace: built-in: git version\ngit version 2.50.1\n"

    Attempted function clauses (showing 1 out of 1):

        defp parse_version(<<"git version ", version::binary>>)

    (mix 1.18.4) lib/mix/scm/git.ex:426: Mix.SCM.Git.parse_version/1
    (mix 1.18.4) lib/mix/scm/git.ex:419: Mix.SCM.Git.git_version/0
    (mix 1.18.4) lib/mix/scm/git.ex:132: Mix.SCM.Git.checkout/2
    (elixir 1.18.4) lib/file.ex:1665: File.cd!/2
    (mix 1.18.4) lib/mix/dep/fetcher.ex:68: Mix.Dep.Fetcher.do_fetch/3
    (mix 1.18.4) lib/mix/dep/converger.ex:238: Mix.Dep.Converger.all/9
    (mix 1.18.4) lib/mix/dep/converger.ex:170: Mix.Dep.Converger.init_all/8
    (mix 1.18.4) lib/mix/dep/converger.ex:110: Mix.Dep.Converger.all/4

This patch updates git_version to handle trace noise by running parse on the final output line of git --version.

New deps.git_test added to exercise the GIT_TRACE condition.

When GIT_TRACE=1 is set in the env, `mix deps.get` fails with an
unexpected `FunctionClauseError` due to `git --version`'s output
including trace output from git itself:

```
λ GIT_TRACE=1 mix deps.get
* Getting ariel (git@github.com:foo/bar.git - main)
22:17:06.786357 git.c:476               trace: built-in: git init --quiet
22:17:06.798692 git.c:476               trace: built-in: git remote add origin git@github.com:foo/bar.git
22:17:06.804333 git.c:476               trace: built-in: git config remote.origin.url git@github.com:foo/bar.git
** (FunctionClauseError) no function clause matching in Mix.SCM.Git.parse_version/1

    The following arguments were given to Mix.SCM.Git.parse_version/1:

        # 1
        "22:17:06.809548 git.c:476               trace: built-in: git version\ngit version 2.50.1\n"

    Attempted function clauses (showing 1 out of 1):

        defp parse_version(<<"git version ", version::binary>>)

    (mix 1.18.4) lib/mix/scm/git.ex:426: Mix.SCM.Git.parse_version/1
    (mix 1.18.4) lib/mix/scm/git.ex:419: Mix.SCM.Git.git_version/0
    (mix 1.18.4) lib/mix/scm/git.ex:132: Mix.SCM.Git.checkout/2
    (elixir 1.18.4) lib/file.ex:1665: File.cd!/2
    (mix 1.18.4) lib/mix/dep/fetcher.ex:68: Mix.Dep.Fetcher.do_fetch/3
    (mix 1.18.4) lib/mix/dep/converger.ex:238: Mix.Dep.Converger.all/9
    (mix 1.18.4) lib/mix/dep/converger.ex:170: Mix.Dep.Converger.init_all/8
    (mix 1.18.4) lib/mix/dep/converger.ex:110: Mix.Dep.Converger.all/4
```

This patch updates `git_version` to handle trace noise by running
parse on the final output line of `git --version`.

New `deps.git_test` added to exercise the `GIT_TRACE` condition.
@josevalim
Copy link
Member

Instead of parsing it, perhaps we should force GIT_TRACE=0?

@tcoopman
Copy link

A bit off-topic, but I've had this same command fail for me, but for a different reason. The terminal printed something before the git version.

The main issue for me was that the error was very obscure and it took me a while to find why this was failing.

I've searched if there was a better way to find the git version, but apparently there isn't 🙁 so I just fixed my terminal output in the end.

@josevalim
Copy link
Member

@tcoopman I see, so we should make this more robust in general. Sounds good.

@josevalim josevalim merged commit bb9721f into elixir-lang:main Dec 17, 2025
10 of 11 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@jeffreylo jeffreylo deleted the jlo/git-trace branch December 17, 2025 12:38
@jeffreylo
Copy link
Contributor Author

thank you, @josevalim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants