Skip to content

Commit 270457f

Browse files
committed
Bail with clear message when file is locked
When attempting to assign a file that is locked by hunks on other commits, the code previously printed a debug-style rejection list and then misleadingly reported success. Instead, fail fast with a user-friendly error that explains the file is locked to other commit(s) and suggests using git to modify commits or move the changes. This prevents confusing output and makes the failure reason clear.
1 parent c1ad39d commit 270457f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/but/src/rub/assign.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use but_workspace::StackId;
33
use colored::Colorize;
44
use gitbutler_command_context::CommandContext;
55

6-
use crate::command;
7-
86
pub(crate) fn assign_file_to_branch(
97
ctx: &mut CommandContext,
108
path: &str,
@@ -79,7 +77,12 @@ fn do_assignments(
7977
) -> anyhow::Result<()> {
8078
let rejections = but_hunk_assignment::assign(ctx, reqs, None)?;
8179
if !rejections.is_empty() {
82-
command::print(&rejections, false)?;
80+
// Don't print the debug output, instead provide a clear error
81+
anyhow::bail!(
82+
"Cannot assign file - it is locked to {} commit{}. Files are locked when they have changes in commits that conflict with the requested assignment. Use git commands to modify commits or move the changes.",
83+
if rejections.len() == 1 { "a" } else { "other" },
84+
if rejections.len() == 1 { "" } else { "s" }
85+
);
8386
}
8487
Ok(())
8588
}

0 commit comments

Comments
 (0)