cli: error out if jj untrack is run at non-head operation

This commit is contained in:
Martin von Zweigbergk 2022-04-19 23:05:00 -07:00 committed by spectral
parent f71047c823
commit 6ec3afc75d
2 changed files with 6 additions and 3 deletions

View file

@ -543,7 +543,7 @@ impl WorkspaceCommandHelper {
fn commit_working_copy(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
if !self.may_update_working_copy {
return Err(UserError(
"Refusing to update working copy (maybe because you're using --at-op)".to_string(),
"Refusing to commit working copy (maybe because you're using --at-op)".to_string(),
));
}
self.maybe_commit_working_copy(ui)?;
@ -1988,9 +1988,8 @@ fn cmd_untrack(
command: &CommandHelper,
args: &UntrackArgs,
) -> Result<(), CommandError> {
// TODO: We should probably check that the repo was loaded at head.
let mut workspace_command = command.workspace_helper(ui)?;
workspace_command.maybe_commit_working_copy(ui)?;
workspace_command.commit_working_copy(ui)?;
let store = workspace_command.repo().store().clone();
let matcher = matcher_from_values(ui, workspace_command.workspace_root(), &args.paths)?;

View file

@ -38,6 +38,10 @@ fn test_untrack() {
std::fs::write(repo_path.join(".gitignore"), "*.bak\n").unwrap();
let files_before = test_env.jj_cmd_success(&repo_path, &["files"]);
// Errors out when not run at the head operation
let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "--at-op", "@-"]);
insta::assert_snapshot!(stderr.replace("jj.exe", "jj"), @"Error: Refusing to commit working copy (maybe because you're using --at-op)
");
// Errors out when no path is specified
let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack"]);
insta::assert_snapshot!(stderr.replace("jj.exe", "jj"), @r###"