cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Allow same source git patches with different rev / branch, etc.

Open 0xdapper opened this issue 3 years ago • 6 comments

Problem

Currently if I wanted to override and patch dependency across workspace of a dependency https://github.com/owner/repo to branch b this does not work

[patch.'https://github.com/owner/repo']
baz = { git = 'https://github.com/owner/repo', branch = 'my-branch' }

because of the input validation here https://github.com/rust-lang/cargo/blob/13662250abdd813755263e0de5623bd314a443db/src/cargo/core/registry.rs#L363-L371

Proposed Solution

Remove the validation or make an exception when the source is a git url?

Notes

No response

0xdapper avatar Jun 14 '22 05:06 0xdapper

Semi-related: https://github.com/rust-lang/cargo/issues/10667

Source replacement for git URL doesn't support rev and branch.

weihanglo avatar Jun 14 '22 12:06 weihanglo

Bumping this up, this is a blocker for private project development where forks are not an option. Patching a project to override a crate dependency with a different branch of the same repo would be the way to go but is impossible right now because of this URL check.

A solution would be to compare the whole package specification (including any tag, branch, commit clause) and block only if every field is the same.

I could start work on a PR for it if this solution makes sense and the interest is there.

fralalonde avatar Mar 14 '23 15:03 fralalonde

I definitely agree that it should be supported in cargo properly, but just to mention a workaround in case it's useful to anyone: it's possible to trick cargo into thinking that it's a different repo by using a double slash in the URL, like this:

[patch.'https://github.com/owner/repo']
baz = { git = 'https://github.com/owner//repo', branch = 'my-branch' }

Cloning https://github.com/owner//repo is the same as cloning https://github.com/owner/repo, so it works.

dimonomid avatar Aug 23 '23 20:08 dimonomid

@dimonomid I have tried this on Windows and I would like to report that it did not work. Maybe this is a linux-only workaround?

PixelDust22 avatar Aug 28 '23 21:08 PixelDust22

I'm not a Windows expert and don't have it around to try it right now, but I didn't expect that it wouldn't work. Could you share what is the error message?

dimonomid avatar Aug 29 '23 06:08 dimonomid

@dimonomid I have tried this on Windows and I would like to report that it did not work. Maybe this is a linux-only workaround?

That's worked for me on windows, also with ssh paths. Corrected workaround, with specifying ssh/https port in patching path:

[patch.'https://github.com/owner/repo']
baz = { git = 'https://github.com:443/owner/repo', branch = 'my-branch' }

juzpermsky avatar Sep 28 '24 09:09 juzpermsky

Just found this is exactly the same issue as https://github.com/rust-lang/cargo/issues/5478. Close in favor of that.

weihanglo avatar Nov 08 '24 21:11 weihanglo