gitbutlerapp/gitbutler · error

Reference step must have a non-empty virtual branch name

Error message

Reference step must have a non-empty virtual branch name

What it means

RebaseStep::validate_step checks each rebase step before execution. A Reference step naming a virtual branch with an empty name is invalid because the reference must identify a real branch; empty names would create ambiguous or unaddressable references during the rebase.

Solutions

  1. Reject empty virtual branch names at the input boundary before building the step
  2. Trim user input and require a non-empty name when creating RebaseStep::Reference
  3. Validate all steps (validate_step) and surface the error before mutating the graph

Example fix

// before
steps.push(RebaseStep::Reference(Reference::Virtual(name))); // name = ""
// after
anyhow::ensure!(!name.trim().is_empty(), "virtual branch name must not be empty");
steps.push(RebaseStep::Reference(Reference::Virtual(name.trim().to_owned())));
Defensive patterns

Strategy: validation

Validate before calling

fn valid_reference_step(step: &RebaseStep) -> bool {
    !matches!(step, RebaseStep::Reference(but_core::Reference::Virtual(n)) if n.trim().is_empty())
}

Type guard

fn non_empty_virtual(name: &str) -> Option<but_core::Reference> {
    (!name.trim().is_empty()).then(|| but_core::Reference::Virtual(name.trim().to_owned()))
}

Try / catch

if let Err(e) = editor.validate_step(&step) {
    anyhow::bail!("rejecting invalid rebase step: {e}");
}

Prevention

When it happens

Trigger: Pushing RebaseStep::Reference(but_core::Reference::Virtual(String::new())) (or an empty virtual branch name sourced from user input or config) into the builder before calling rebase().

Common situations: UI/CLI layers passing an unvalidated branch-name field straight through, or deserialized steps from JSON where the name field was an empty string.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/02d979e3ad9071d2. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-rebase/src/lib.rs:196

        match step {
            RebaseStep::Pick { commit_id, .. } => {
                self.assure_unique_step_and_existing_non_base(commit_id, "Picked")?;
            }
            RebaseStep::SquashIntoPreceding {
                commit_id,
                new_message: _,
            } => {
                self.assure_unique_step_and_existing_non_base(commit_id, "Fixup")?;
                if matches!(self.steps.last(), Some(RebaseStep::Reference { .. })) {
                    bail!("Fixup commit must not come after a reference step");
                }
                if self.steps.is_empty() {
                    bail!("Fixup must have a commit to work on");
                }
            }
            RebaseStep::Reference(name) => {
                if matches!(name, but_core::Reference::Virtual(name) if name.is_empty()) {
                    return Err(anyhow!(
                        "Reference step must have a non-empty virtual branch name"
                    ));
                }
            }
        }
        Ok(())
    }

    fn assure_unique_step_and_existing_non_base(
        &self,
        commit_id: &gix::oid,
        kind: &str,
    ) -> Result<()> {
        self.repo.find_commit(commit_id)?;
        if Some(commit_id) == self.base.as_deref() {
            bail!("{kind} commit cannot be the base commit");
        }
        if self.steps.iter().any(|s| s.commit_id() == Some(commit_id)) {

View on GitHub (pinned to 58e5313667)