Skip to content

Resolve Rust git cli: dependency installs by package name lookup#1688

Closed
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-additional-dependencies-rust-hooks
Closed

Resolve Rust git cli: dependency installs by package name lookup#1688
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-additional-dependencies-rust-hooks

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

Rust hooks with additional_dependencies like cli:https://...[:rev] can fail on repositories containing multiple binary packages because cargo install --git needs an explicit package selection. This change resolves the package from the hook entry binary and installs that package directly.

  • Dependency parsing + package resolution

    • Added a shared parser for Rust cli: dependency strings (git URL + optional rev, or crate + optional version).
    • For git dependencies, clone the target repo/rev and use existing find_package_dir to map entry binary → owning package name.
  • Cargo install invocation

    • Updated git dependency install args to pass the resolved package name to cargo install --git (instead of passing --bin).
    • Non-git cli: dependency behavior is unchanged.
  • Focused test updates

    • Added unit coverage for dependency parsing behavior.
    • Added a focused async test for non-git package resolution short-circuit.
    • Updated CLI dependency argument-format tests to reflect package-based git installs.
// before (git cli dep)
cargo install --bins --root <env> --git https://github.com/fish-shell/fish-shell --tag 4.5.0 --bin fish_indent --locked

// now
cargo install --bins --root <env> --git https://github.com/fish-shell/fish-shell --tag 4.5.0 fish --locked

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/fish-shell/fish-shell/commits/4.5.0
    • Triggering command: /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/bin/cargo install --bins --root /home/REDACTED/.cache/prek/hooks/rust-AAocD40ReYOKrbqAn9pU --git REDACTED --tag 4.5.0 fish --locked relro jrqe�� ut86njw4vrlq8d4nhg.1iypvdb.rcgu.o v63463rj7jg9399o56.1iypvdb.rcgu.o /opt/pipx_bin/ginow -c core.autocrlf=fa-c -c git (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Unable to use additional_dependencies with Rust hooks in repos that have multiple binaries</issue_title>
<issue_description>### Summary

I'm trying to add a pre-commit hook for the latest fish_indent, as seen in the config below, but I get this error:

prek install-hooks
error: Failed to install hook `fish_indent`
  caused by: Command `install cli dep` exited with an error:

[status]
exit status: 101

[stderr]
Updating git repository `https://github.com/fish-shell/fish-shell`
error: multiple packages with binaries found: fish, xtask. When installing a git repository, cargo will always search the entire repo for any Cargo.toml.
Please specify a package, e.g. `cargo install --git https://github.com/fish-shell/fish-shell fish`.

Willing to submit a PR?

  • Yes — I’m willing to open a PR to fix this.

Platform

Darwin 24.6.0 arm64

Version

prek 0.3.3 (Homebrew 2026-02-15)

.pre-commit-config.yaml

repos:
  - repo: local
    hooks:
      - id: fish_indent
        name: fish_indent
        language: rust
        additional_dependencies:
          - cli:https://github.com/fish-shell/fish-shell:4.5.0
        entry: fish_indent
        args: [-w]
        files: .+\.fish

Log file

2026-02-21T04:31:40.253240Z DEBUG prek: 0.3.3 (Homebrew 2026-02-15)
2026-02-21T04:31:40.253301Z DEBUG Args: ["prek", "-vvv", "install-hooks"]
2026-02-21T04:31:40.264213Z TRACE get_root: close time.busy=10.8ms time.idle=54.2µs
2026-02-21T04:31:40.264253Z DEBUG Git root: /Users/andy/tmp/prek-rust-fish_indent
2026-02-21T04:31:40.264287Z DEBUG Found workspace root at `/Users/andy/tmp/prek-rust-fish_indent`
2026-02-21T04:31:40.264300Z TRACE Include selectors: ``
2026-02-21T04:31:40.264307Z TRACE Skip selectors: ``
2026-02-21T04:31:40.264412Z DEBUG discover{root="/Users/andy/tmp/prek-rust-fish_indent" config=None refresh=false}: Loaded workspace from cache
2026-02-21T04:31:40.264445Z DEBUG discover{root="/Users/andy/tmp/prek-rust-fish_indent" config=None refresh=false}: Loading project configuration path=.pre-commit-config.yaml
2026-02-21T04:31:40.265072Z TRACE discover{root="/Users/andy/tmp/prek-rust-fish_indent" config=None refresh=false}: close time.busy=736µs time.idle=12.2µs
2026-02-21T04:31:40.265281Z TRACE Checking lock resource="store" path=/Users/andy/.cache/prek/.lock
2026-02-21T04:31:40.265300Z DEBUG Acquired lock resource="store"
2026-02-21T04:31:40.266737Z TRACE Using system installed rustup at /Users/andy/.cargo/bin/rustup
2026-02-21T04:31:40.266840Z TRACE Checking lock resource="rustup" path=/Users/andy/.cache/prek/tools/rustup/.lock
2026-02-21T04:31:40.266853Z DEBUG Acquired lock resource="rustup"
2026-02-21T04:31:40.266881Z TRACE Executing `/Users/andy/.cargo/bin/rustup toolchain list -v`
2026-02-21T04:31:40.278184Z TRACE Executing `/Users/andy/.cargo/bin/rustup toolchain list -v`
2026-02-21T04:31:40.288828Z TRACE Executing `/Users/andy/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --version`
2026-02-21T04:31:40.289086Z TRACE Executing `/Users/andy/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/rustc --version`
2026-02-21T04:31:40.306240Z TRACE Found matching system rust name=nightly-aarch64-apple-darwin
2026-02-21T04:31:40.306276Z TRACE Using system rust rust=/Users/andy/.rustup/toolchains/nightly-aarch64-apple-darwin@1.95.0-nightly
2026-02-21T04:31:40.306289Z TRACE Released lock path=/Users/andy/.cache/prek/tools/rustup/.lock
2026-02-21T04:31:40.306524Z TRACE Executing `/Users/andy/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo install --bins --root /Users/andy/.cache/prek/hooks/rust-To61QTPD8Vc5UN6OVBvK --git https://github.com/fish-shell/fish-shell [...]`
2026-02-21T04:31:40.599658Z TRACE Released lock path=/Users/andy/.cache/prek/.lock
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix additional_dependencies issue with Rust hooks for multiple binaries Fix Rust cli: hook installs for multi-binary git repositories Feb 22, 2026
Copilot AI requested a review from j178 February 22, 2026 10:02
@j178
Copy link
Owner

j178 commented Feb 22, 2026

@copilot I think we already use --bins in cargo install, isn't that collision with --bin?

Copy link
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot I think we already use --bins in cargo install, isn't that collision with --bin?

Good question. I verified this: Cargo accepts --bins together with --bin <name> (no flag conflict error). In this case, --bin is the key part for git repos with multiple packages/binaries because it gives Cargo a concrete target to resolve; --bins remains from the existing install invocation pattern.

@j178
Copy link
Owner

j178 commented Feb 27, 2026

@copilot use find_package_dir to find the package for the binary in the entry, and pass the package name to the cargo install instead.

Copilot AI and others added 2 commits February 27, 2026 15:11
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
Copilot AI changed the title Fix Rust cli: hook installs for multi-binary git repositories Resolve Rust git cli: dependency installs by package name lookup Feb 27, 2026
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot use find_package_dir to find the package for the binary in the entry, and pass the package name to the cargo install instead.

Implemented in 91dcc4b: for git cli: dependencies we now resolve the package from the hook entry binary via find_package_dir and pass that package name to cargo install --git.

@j178 j178 closed this Mar 6, 2026
@j178 j178 deleted the copilot/fix-additional-dependencies-rust-hooks branch March 6, 2026 11:10
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.

Unable to use additional_dependencies with Rust hooks in repos that have multiple binaries

2 participants