-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: Support install directly from git repo #1162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally good, some notes and questions
/// Override how to fetch Cargo.toml package manifest. | ||
/// | ||
/// This skip searching crates.io and instead clone the repository specified and | ||
/// runs as if `--manifest-path $cloned_repo` is passed to binstall. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be for a future improvement, but would be useful to consider supporting some syntax or options for:
- Branches/refs other than default
- Subpaths in the repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can support that by using fragment, e.g.
https://github.com/cargo-bins/cargo-binstall#branch=...#subpath=...
or maybe using query:
https://github.com/cargo-bins/cargo-binstall?branch=...?subpath=...
Not sure which one is more compatible with git url, I need more advice on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think doing whatever cargo and/or npm does is a good default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah and that will be compatible with cargo-install
:
--git url
Git URL to install the specified crate from.
--branch branch
Branch to use when installing from git.
--tag tag
Tag to use when installing from git.
--rev sha
Specific commit to use when installing from git.
so we would have to at least support --branch
/--tag
/--rev
just like cargo-install
.
I think cargo-install
finds the Cargo.toml
by the package name, so we can also do that in cargo-binstall
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Byron I tried searching for how to checkout branch in gitoxide but only found this GitoxideLabs/gitoxide#358 which uses low-level APIs.
I also checked gix::Repository
but I also failed to find one, seems like only way is to dive into the low-level APIs of gix
to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed, the combination of choosing a refspec that fetches the desired branch and checking out its tree afterwards is how --branch
would be implemented. The question of how to deal with the implementation's limitations would still have to be answered though.
Though I didn't know there's a filter in gix.
I don't know what filter
means in this context. Feel free to ignore if everything is clear to you though.
I might need to take a look at PRs linked with rust-lang/cargo#11813 to see how they accomplish this.
cargo
still performs checkouts using git2
, and it's what I will be working to change from now on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed, the combination of choosing a refspec that fetches the desired branch and checking out its tree afterwards is how --branch would be implemented.
Thanks for confirmation of this!
This goes by the big caveat that filters aren't applied and that it will panic on submodules (not implemented) - checking things out is generally not ready yet even though it works well enough for some cases.
Well that's unfortunate.
Our goal here is to have the same behavior as cargo-install
when --git
is passed.
I'm not sure whether it clones submodules though.
cargo
still performs checkouts usinggit2
, and it's what I will be working to change from now on.
Thanks for the info, I will keep track of the adoption of gitoxide
in cargo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried
prepare_fetch =
set_fetch_refspec(prepare_fetch, format!("+refs/heads/main:refs/remotes/origin/{branch}"));
fn set_fetch_refspec(prepare_fetch: clone::PrepareFetch, refspec: String) -> clone::PrepareFetch {
prepare_fetch.configure_remote(move |mut remote| {
remote.replace_refspecs([refspec.as_bytes()], remote::Direction::Fetch)?;
Ok(remote)
})
}
but somehow it still clones main.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be too hard to get everything done in one PR, while gix
doesn't support checking out specific branch/tag/rev at clone.
I will open a new tracking issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened tracking issue #1165 for this.
70b41d4
to
3b76ab3
Compare
Fixed #3 Signed-off-by: Jiahao XU <[email protected]>
Fixed #3