rust-lang/cargo · error

unstable 'gitoxide' only takes `fetch` and `checkout` as val

Error message

unstable 'gitoxide' only takes `fetch` and `checkout` as valid inputs, for shallow fetches see `-Zgit=shallow-index,shallow-deps`

What it means

`GitoxideFeatures::parse_gitoxide` validates the values given to the unstable `-Zgit` flag (via `visit_str`/`add`). Only `fetch` and `checkout` are accepted; any other token causes this bail. The message also points to `-Zgit=shallow-index,shallow-deps` for shallow-fetch related options.

Source

Thrown at src/workspace/features.rs:1235

            Ok(Some(GitoxideFeatures::deserialize(mvd)?))
        }
    }

    deserializer.deserialize_any(GitoxideFeaturesVisitor)
}

fn parse_gitoxide(
    it: impl Iterator<Item = impl AsRef<str>>,
) -> CargoResult<Option<GitoxideFeatures>> {
    let mut out = GitoxideFeatures::default();
    let GitoxideFeatures { fetch, checkout } = &mut out;

    for e in it {
        match e.as_ref() {
            "fetch" => *fetch = true,
            "checkout" => *checkout = true,
            _ => {
                bail!(GitoxideFeatures::expecting())
            }
        }
    }
    Ok(Some(out))
}

impl CliUnstable {
    /// Parses `-Z` flags from the command line, and returns messages that warn
    /// if any flag has already been stabilized.
    pub fn parse(
        &mut self,
        flags: &[String],
        nightly_features_allowed: bool,
    ) -> CargoResult<Vec<String>> {
        if !flags.is_empty() && !nightly_features_allowed {
            bail!(
                "the `-Z` flag is only accepted on the nightly channel of Cargo, \
                 but this is the `{}` channel\n\

View on GitHub (pinned to 42eee92bc9)

Solutions

  1. Use only `-Zgit=fetch` and/or `-Zgit=checkout` (e.g. `-Zgit=fetch,checkout`).
  2. For shallow clones of git dependencies, use `-Zgit=shallow-index,shallow-deps` instead.
  3. Check `cargo -Z help` / current nightly docs for the valid token list, as unstable flags change between releases.
  4. Remove the `-Zgit` flag entirely on stable Rust, where it is not accepted anyway.

Example fix

// before
cargo +nightly build -Zgit=shallow
// after
cargo +nightly build -Zgit=fetch,checkout -Zgit=shallow-index,shallow-deps
Defensive patterns

Strategy: validation

Validate before calling

let valid = ["fetch", "checkout"];
for tok in std::env::args().filter(|a| a.starts_with("-Zgit=")) {
    for v in tok.trim_start_matches("-Zgit=").split(',') {
        assert!(valid.contains(&v) || v.starts_with("shallow"), "invalid -Zgit value: {v}");
    }
}

Prevention

When it happens

Trigger: Invoking cargo with a nightly `-Zgit` value other than `fetch` or `checkout`, e.g. `-Zgit=shallow` or `-Zgit=fetch,shallow`, or RUSTC_BOOTSTRAP-based `-Zgit` in RUSTFLAGS/config env.

Common situations: Following outdated blog posts/issues that reference renamed or removed gitoxide feature tokens; typos like `fech`; confusing the shallow-fetch flags with the gitoxide feature list.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of rust-lang/cargo@42eee92bc9 (2026-09-08). Data as JSON: /api/errors/2b9f5b934c36ffa8. Report an issue: GitHub.