Skip to content
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

Merged
merged 1 commit into from
Jun 24, 2023
Merged

feat: Support install directly from git repo #1162

merged 1 commit into from
Jun 24, 2023

Conversation

NobodyXu
Copy link
Member

Fixed #3

Copy link
Member

@passcod passcod left a 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

crates/bin/src/args.rs Outdated Show resolved Hide resolved
crates/binstalk/Cargo.toml Outdated Show resolved Hide resolved
crates/binstalk/src/helpers/git.rs Outdated Show resolved Hide resolved
crates/binstalk/src/helpers/git.rs Show resolved Hide resolved
crates/bin/src/args.rs Show resolved Hide resolved
/// 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.
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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 using git2, 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

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@NobodyXu NobodyXu force-pushed the feat/git branch 6 times, most recently from 70b41d4 to 3b76ab3 Compare June 23, 2023 10:31
@NobodyXu NobodyXu added this pull request to the merge queue Jun 24, 2023
Merged via the queue into main with commit ca00cba Jun 24, 2023
@NobodyXu NobodyXu deleted the feat/git branch June 24, 2023 01:22
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.

Support install directly from git repo
3 participants