CARGO_GIT_WRAPPER variable and GITLAB cicd scripts
⚓ Rust 📅 2025-10-04 👤 surdeus 👁️ 7I think you would call this a "feature request"
I need a means to force CARGO to use a script wrapper for all GIT operations.
We already gave up on "libgit2" - it does not work in our environment we already use the: git-fetch-with-cli feature as a standard workaround to make anything with GIT work.
What I think I need/want and I am suggesting is this:
For example cargo has this existing ENV variable it supports.
RUSTC_WRAPPER — Instead of simply running rustc
Perhaps what is required is this:
CARGO_GIT_WRAPPER - instead of simply running 'git' - run this command
I do not see anything like it on the Cargo ENV document page:
The specific problem is this:
During normal use - ie: me typing cargo commands etc - Cargo can use the standard GIT command line tool.
In that case - git can access my ssh keys, the URL is correct etc. THUS - cargo can pull crates from our GIT REPO in the normal way using a git/ssh based URL.
HOWEVER - in the GITLAB CI?CD process the GITLAB RUNNER provides an HTTP session token to fetch from the GITLAB Server. That URL is very different.
Our other tools have "git url rewriters" that trigger off of the GITLAB runner variables like: CI=true and rewrite GIT URLS as needed.
Effectively this means I require two different URLS in the Cargo.toml file -
- Url #1 the SSH based URL when we are not in the CI/CD operation and
- URL #2 An HTTPS based when we are in the GITLAB CICD operation.
That URL#2 is a HTTPS + CI_TOKEN based URL that only works under that specific CI session (the token expires at the end of the CI Pipeline)
I believe the easy means to solve this is in a script
Before you suggest it: I know that GIT has rewrite (instead of?) rules that help - but these are unique to the user and need to be only used if and only if we are in the CI?CD situation (ie: Gitlab provides a number of CI/CD environment variables)
The only work around I think I can do for now is the following - and it is nasty. Hence this suggestion/feature-request.
a) In my GITLAB CI script - insert a SHIM directory in the front of my ${PATH}, before executing "cargo build" or "cargo test" - that SHIM directory would have a "git" replacement script - that rewrites the URL..
b) That script would then remove its directory from the PATH (without the SHIM dir) and re-execute the normal GIT command with the updated/edited URL.
Ugly.
4 posts - 2 participants
🏷️ Rust_feed