Skip to content

feat(manager/cargo): support git dependencies #36444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

okkero
Copy link
Contributor

@okkero okkero commented Jun 11, 2025

Changes

This PR reintroduces Cargo git dependencies, reverted in #36412. The original PR adding support for git dependencies also introduced two regressions. This PR addresses both:

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

mkniewallner and others added 10 commits November 2, 2024 15:47
…ult to '*' instead of crashing.

This is necessary in cases where you have a git dependency without a
specified ref (no `rev`, `tag` or `branch`)
`cargo` versioning never makes sense for git dependencies, since the ref
always has to be an exact match.

If the current value looks like semver, we use `semver` versioning.
Otherwise we use `loose` versioning.
@viceice viceice self-requested a review June 11, 2025 07:23
Copy link
Collaborator

@RahulGautamSingh RahulGautamSingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except the comments and the protocol change situation

@okkero okkero requested a review from RahulGautamSingh July 7, 2025 11:30
@@ -20,7 +20,8 @@ export function applyGitSource(
platform === 'github'
? GithubTagsDatasource.id
: GitlabTagsDatasource.id;
const { protocol, source, full_name } = parseGitUrl(git);
const httpUrl = getHttpUrl(git);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this working fine on your test repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I tested with git dependencies both using URLs of the form https://github.com/... and ssh://git@github.com/..., and they both work. Did you have any concerns about this? An edge case I may not be aware of?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you case didn't occur earlier as we use the same function at other places for the same purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That I don't know. The dependency update breaks without this when using ssh://git@github.com/... style URLs with tags in the Cargo.toml. Here is the Cargo.toml file used, and this is the error message I get:

 INFO: Renovate is exiting with a non-zero code due to the following logged errors
       "loggerErrors": [
         {
           "name": "renovate",
           "level": 50,
           "logContext": "h4eoLGnOiFF5APflydRsn",
           "repository": "okkero/renovate-test",
           "url": "/graphql",
           "baseUrl": "ssh://github.com/api/",
           "resolvedUrl": "ssh://github.com/api/graphql",
           "msg": "Request Error: cannot parse url"
         }
       ]

I see that massageUrl does something similar, although it seems more thorough and that it covers more cases.

Should we reuse that here instead? Or should this replacement be done at a different level entirely? I mean, it seems to me that this has to be done at some point or other, but I don't know what would be the best way to go about it...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that would work, @RahulGautamSingh , or do you recommend another approach? It just seems that the protocol for the registry URL can't be ssh, even though cargo supports it. So, the GitHub API must be called through https, which makes sense, so it has to be converted at some point. I am just unsure where exactly it would be best to do that.

Comment on lines -285 to -292
"currentValue": "0.1.0",
"datasource": "crate",
"currentValue": undefined,
"datasource": "git-refs",
"depName": "git_dep_with_version",
"depType": "dependencies",
"managerData": {
"nestedVersion": true,
},
"skipReason": "git-dependency",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version was detected before, but now it is unspecified? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Why is currentValue now undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, hmm. So, for cargo git dependencies, the version field does not specify which version of the crate to fetch, but may exist alongside branch, rev or tag as a sort of sanity check: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#the-role-of-the-version-key

So, to me it seems correct that currentValue would be unspecified in this case, but I'm not exactly sure what to do with the version key for git dependencies, or whether we should do anything at all.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please point to me which change cause this? I am unable to find the change that triggered this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -20,7 +20,8 @@ export function applyGitSource(
platform === 'github'
? GithubTagsDatasource.id
: GitlabTagsDatasource.id;
const { protocol, source, full_name } = parseGitUrl(git);
const httpUrl = getHttpUrl(git);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you case didn't occur earlier as we use the same function at other places for the same purpose.

Comment on lines -285 to -292
"currentValue": "0.1.0",
"datasource": "crate",
"currentValue": undefined,
"datasource": "git-refs",
"depName": "git_dep_with_version",
"depType": "dependencies",
"managerData": {
"nestedVersion": true,
},
"skipReason": "git-dependency",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please point to me which change cause this? I am unable to find the change that triggered this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. These were added before I took over the PR. Perhaps @mkniewallner can fill us in?

I tried removing these, and then two tests broke. It's not clear to me exactly what's happening here.

 FAIL  lib/modules/manager/cargo/artifacts.spec.ts > modules/manager/cargo/artifacts > returns updated Cargo.lock with precise version update
AssertionError: expected [ { …(2) } ] to match object [ …(2) ]

- Expected
+ Received

  [
    {
      "cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path Cargo.toml --workspace",
+     "options": {
+       "cwd": "/tmp/github/some/repo",
+       "encoding": "utf-8",
+       "env": {
+         "HOME": "/home/user",
+         "HTTPS_PROXY": "https://example.com",
+         "HTTP_PROXY": "http://example.com",
+         "LANG": "en_US.UTF-8",
+         "LC_ALL": "en_US",
+         "NO_PROXY": "localhost",
+         "PATH": "/tmp/path",
        },
-   {
-     "cmd": "cargo update --config net.git-fetch-with-cli=true --manifest-path Cargo.toml --package dep1@1.0.0 --precise 1.0.1",
+       "maxBuffer": 10485760,
+       "timeout": 900000,
+     },
    },
  ]

 ❯ lib/modules/manager/cargo/artifacts.spec.ts:142:27
    140|       { file: { contents: undefined, path: 'Cargo.lock', type: 'addition' } },
    141|     ]);
    142|     expect(execSnapshots).toMatchObject([
       |                           ^
    143|       {
    144|         cmd:
 FAIL  lib/modules/manager/cargo/artifacts.spec.ts > modules/manager/cargo/artifacts > returns updated Cargo.lock when a preceding dependency triggers an update in a later dependency
AssertionError: expected [ Array(1) ] to deeply equal [ { file: { …(3) } } ]

- Expected
+ Received

  [
    {
      "file": {
-       "contents": undefined,
+       "contents": "
+       [[package]]
+       name = \"dep1\"
+       version = \"1.0.1\"
+
+       [[package]]
+       name = \"dep2\"
+       version = \"1.0.2\"
+
+       [[package]]
+       name = \"dep3\"
+       version = \"1.0.0\"
+     ",
        "path": "Cargo.lock",
        "type": "addition",
      },
    },
  ]

 ❯ lib/modules/manager/cargo/artifacts.spec.ts:310:7
    308|         config,
    309|       }),
    310|     ).toEqual([
       |       ^
    311|       { file: { contents: undefined, path: 'Cargo.lock', type: 'addition' } },
    312|     ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(manager/cargo): support for git dependencies
5 participants