gitbutlerapp/gitbutler · error

Topic cannot be empty

Error message

Topic cannot be empty

What it means

With gerrit mode on, `--topic` is trimmed and must be non-empty before becoming `but_gerrit::PushFlag::Topic`; whitespace-only input is rejected because Gerrit topics group related changes and cannot be blank. If you want the branch name as the topic, `--topic-from-branch` derives it in the same function without needing --topic.

Source

Thrown at crates/but/src/command/legacy/push.rs:1083

    if args.wip {
        flags.push(but_gerrit::PushFlag::Wip);
    } else {
        // Default to Ready, or explicit Ready
        flags.push(but_gerrit::PushFlag::Ready);
    }

    // Handle hashtags - can be multiple
    for hashtag in &args.hashtag {
        if hashtag.trim().is_empty() {
            return Err(anyhow::anyhow!("Hashtag cannot be empty"));
        }
        flags.push(but_gerrit::PushFlag::Hashtag(hashtag.clone()));
    }

    // Handle topic - at most one
    if let Some(topic) = &args.topic {
        if topic.trim().is_empty() {
            return Err(anyhow::anyhow!("Topic cannot be empty"));
        }
        flags.push(but_gerrit::PushFlag::Topic(topic.clone()));
    } else if args.topic_from_branch {
        flags.push(but_gerrit::PushFlag::Topic(branch_name.to_string()));
    }

    // Handle private flag
    if args.private {
        flags.push(but_gerrit::PushFlag::Private);
    }

    Ok(flags)
}

fn resolve_branch_name(
    ctx: &mut Context,
    id_map: &IdMap,
    branch_id: &str,

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Give --topic a real value: `but push --topic my-topic`
  2. Or use `but push --topic-from-branch` to derive the topic from the branch name
  3. Remove the flag entirely if no topic is needed

Example fix

# before
but push --topic ""
# error: Topic cannot be empty

# after
but push --topic my-topic
# or
but push --topic-from-branch
Defensive patterns

Strategy: validation

Validate before calling

# Validate the topic before pushing
[ -n "${topic//[[:space:]]/}" ] || { echo 'empty --topic' >&2; exit 1; }
but push --topic "$topic"

Prevention

When it happens

Trigger: Running `but push --topic ""` or `--topic " "` in a Gerrit-enabled repo, typically via an unset variable in a script.

Common situations: Empty CI variable forwarded as --topic; placeholder topic never replaced; interactive script bug producing blank input.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/e7ee1bd0c623c3cc. Report an issue: GitHub.