ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: separate out hint in untrack message

This commit is contained in:
Martin von Zweigbergk 2022-11-12 15:48:25 -08:00 committed by Martin von Zweigbergk
parent 6a15cc02bf
commit 698bba387f
2 changed files with 14 additions and 12 deletions

View file

@ -1164,19 +1164,18 @@ fn cmd_untrack(
let ui_path = workspace_command.format_file_path(path); let ui_path = workspace_command.format_file_path(path);
let message = if added_back.len() > 1 { let message = if added_back.len() > 1 {
format!( format!(
"'{}' and {} other files would be added back because they're not ignored. \ "'{}' and {} other files are not ignored.",
Make sure they're ignored, then try again.",
ui_path, ui_path,
added_back.len() - 1 added_back.len() - 1
) )
} else { } else {
format!( format!("'{}' is not ignored.", ui_path)
"'{}' would be added back because it's not ignored. Make sure it's ignored, \
then try again.",
ui_path
)
}; };
return Err(user_error(message)); return Err(user_error_with_hint(
message,
"Files that are not ignored will be added back by the next command.
Make sure they're ignored, then try again.",
));
} else { } else {
// This means there were some concurrent changes made in the working copy. We // This means there were some concurrent changes made in the working copy. We
// don't want to mix those in, so reset the working copy again. // don't want to mix those in, so reset the working copy again.

View file

@ -53,8 +53,11 @@ fn test_untrack() {
test_env.jj_cmd_cli_error(&repo_path, &["untrack"]); test_env.jj_cmd_cli_error(&repo_path, &["untrack"]);
// Errors out when a specified file is not ignored // Errors out when a specified file is not ignored
let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "file1.bak"]); let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "file1.bak"]);
insta::assert_snapshot!(stderr, @"Error: 'file1' would be added back because it's not ignored. Make sure it's ignored, \ insta::assert_snapshot!(stderr, @r###"
then try again.\n"); Error: 'file1' is not ignored.
Hint: Files that are not ignored will be added back by the next command.
Make sure they're ignored, then try again.
"###);
let files_after = test_env.jj_cmd_success(&repo_path, &["files"]); let files_after = test_env.jj_cmd_success(&repo_path, &["files"]);
// There should be no changes to the state when there was an error // There should be no changes to the state when there was an error
assert_eq!(files_after, files_before); assert_eq!(files_after, files_before);
@ -77,8 +80,8 @@ fn test_untrack() {
assert_eq!( assert_eq!(
stderr, stderr,
format!( format!(
"Error: '{}' and 1 other files would be added back because they're not ignored. Make \ "Error: '{}' and 1 other files are not ignored.\nHint: Files that are not ignored \
sure they're ignored, then try again.\n", will be added back by the next command.\nMake sure they're ignored, then try again.\n",
PathBuf::from("target").join("file2").display() PathBuf::from("target").join("file2").display()
) )
); );