{"record":{"id":"476099b9974b74f5","repo":"gitbutlerapp/gitbutler","slug":"aborting-due-to-empty-branch-name","errorCode":null,"errorMessage":"Aborting due to empty branch name","messagePattern":"Aborting due to empty branch name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/reword2.rs","lineNumber":235,"sourceCode":"\n    Ok(operation)\n}\n\npub(crate) fn get_branch_name_from_editor(current_name: &str) -> anyhow::Result<String> {\n    let mut template = String::new();\n    template.push_str(current_name);\n    if !current_name.is_empty() && !current_name.ends_with('\\n') {\n        template.push('\\n');\n    }\n    template.push_str(\"\\n# Please enter the new branch name. Lines starting\\n\");\n    template.push_str(\"# with '#' will be ignored, and an empty name aborts the operation.\\n\");\n    template.push_str(\"#\\n\");\n\n    let branch_name =\n        crate::tui::get_text::from_editor_no_comments(\"branch_name\", &template)?.to_string();\n    let branch_name = branch_name.trim();\n    if branch_name.is_empty() {\n        anyhow::bail!(\"Aborting due to empty branch name\");\n    }\n    Ok(branch_name.to_owned())\n}\n\npub fn run(\n    ctx: &mut Context,\n    meta: &mut impl RefMetadata,\n    perm: &mut RepoExclusive,\n    operation: RewordOperation,\n) -> CliResult<(RewordOutcome, Option<WorkspaceState>)> {\n    match operation {\n        RewordOperation::Commit {\n            target,\n            new_message: message,\n        } => {\n            let commit_details = {\n                let repo = ctx.repo.get()?;\n                CommitDetails::from_commit_id(","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/reword2.rs#L217-L253","documentation":"The `but` CLI opens the user's editor to collect a new branch name during branch-reword/creation flows (`get_branch_name_from_editor`). After the editor closes, the trimmed text is checked and if nothing remains the command aborts with this error instead of creating an empty-named branch, which Git refs cannot represent.","triggerScenarios":"Calling `but branch create`, `but branch reword`/edit-name flows where the user (or a scripted `GIT_EDITOR`) closes the editor with an empty file, deletes all typed content, or leaves only comment lines that `from_editor_no_comments` strips out.","commonSituations":"Running the command non-interactively with an editor like `true` or `:` as GIT_EDITOR; automating the CLI in CI with a misconfigured editor; a user accidentally clearing the editor buffer; templates whose only content is `#` comment lines.","solutions":["Re-run the command and type a valid branch name before saving and closing the editor","Ensure GIT_EDITOR/EDITOR/core.editor points to an editor that actually saves content (not `true`, `cat > /dev/null`, etc.)","When scripting, pre-seed or pipe the desired branch name instead of relying on the interactive editor","Check the saved file has no leading/trailing whitespace-only content; comments starting with `#` are stripped"],"exampleFix":"// before (scripted, always aborts)\nGIT_EDITOR=true but branch create\n\n// after (provide a real name via editor content or a non-interactive path)\nexport GIT_EDITOR=\"sh -c 'echo my-branch > \"$1\"' --\"\nbut branch create","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# ensure the editor produces non-empty, non-comment content\nname=$(git var GIT_EDITOR >/dev/null 2>&1 && echo ok)\n[ -n \"$name\" ] || { echo \"no editor configured\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match but_branch_create_result {\n    Err(e) if e.to_string().contains(\"Aborting due to empty branch name\") => {\n        eprintln!(\"editor produced an empty branch name; retry with a name\");\n    }\n    other => other?,\n}","preventionTips":["Configure GIT_EDITOR/EDITOR to a real editor, never `true` or `:`","When automating, write the branch name into the editor temp file from your script","Remember lines starting with `#` are stripped as comments; don't rely on them for the name","Trim-check content before saving in scripted editor wrappers"],"tags":["cli","git","branch-name","user-input","validation"],"backgroundTag":"empty-required-field","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}