From 698bba387f3d74987621f428a04e12cf60ace7c5 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 12 Nov 2022 15:48:25 -0800 Subject: [PATCH] cli: separate out hint in `untrack` message --- src/commands.rs | 15 +++++++-------- tests/test_untrack_command.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 24351ceb2..9a483b9d0 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1164,19 +1164,18 @@ fn cmd_untrack( let ui_path = workspace_command.format_file_path(path); let message = if added_back.len() > 1 { format!( - "'{}' and {} other files would be added back because they're not ignored. \ - Make sure they're ignored, then try again.", + "'{}' and {} other files are not ignored.", ui_path, added_back.len() - 1 ) } else { - format!( - "'{}' would be added back because it's not ignored. Make sure it's ignored, \ - then try again.", - ui_path - ) + format!("'{}' is not ignored.", 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 { // 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. diff --git a/tests/test_untrack_command.rs b/tests/test_untrack_command.rs index cf654bf77..23bc0114c 100644 --- a/tests/test_untrack_command.rs +++ b/tests/test_untrack_command.rs @@ -53,8 +53,11 @@ fn test_untrack() { test_env.jj_cmd_cli_error(&repo_path, &["untrack"]); // Errors out when a specified file is not ignored 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, \ - then try again.\n"); + insta::assert_snapshot!(stderr, @r###" + 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"]); // There should be no changes to the state when there was an error assert_eq!(files_after, files_before); @@ -77,8 +80,8 @@ fn test_untrack() { assert_eq!( stderr, format!( - "Error: '{}' and 1 other files would be added back because they're not ignored. Make \ - sure they're ignored, then try again.\n", + "Error: '{}' and 1 other files are not ignored.\nHint: Files that are not ignored \ + will be added back by the next command.\nMake sure they're ignored, then try again.\n", PathBuf::from("target").join("file2").display() ) );