From 6ec3afc75d7882cd3ffe6b3659fab14ec9ce7879 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 19 Apr 2022 23:05:00 -0700 Subject: [PATCH] cli: error out if `jj untrack` is run at non-head operation --- src/commands.rs | 5 ++--- tests/test_untrack_command.rs | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 693570321..d538524ed 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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)?; diff --git a/tests/test_untrack_command.rs b/tests/test_untrack_command.rs index 9c8f26785..f239065b5 100644 --- a/tests/test_untrack_command.rs +++ b/tests/test_untrack_command.rs @@ -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###"