diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index 4aa87af6a1..0c7a493588 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -295,12 +295,27 @@ impl From for CommandError { impl From for CommandError { fn from(err: SnapshotError) -> Self { match err { - SnapshotError::NewFileTooLarge { .. } => { - user_error_with_message("Failed to snapshot the working copy", err).hinted( - r#"Increase the value of the `snapshot.max-new-file-size` config option if you -want this file to be snapshotted. Otherwise add it to your `.gitignore` file."#, - ) - } + SnapshotError::NewFileTooLarge { + path, + size, + max_size, + } => user_error(format!( + "Failed to snapshot the working copy\nThe file '{}' is too large to be \ + snapshotted ({} bytes).\nThe maximum size allowed is {} bytes.", + path.display(), + size.0, + max_size.0 + )) + .hinted(format!( + "This is to prevent large files from being added on accident. You can fix this \ + error by: + - Adding the file to `.gitignore` + - Run `jj config set --repo snapshot.max-new-file-size \"{}B\"` + This will increase the maximum file size allowed for new files, in this repository only. + - Run `jj --config-toml 'snapshot.max-new-file-size=\"{}B\"' st` + This will increase the maximum file size allowed for new files, for this command only.", + size.0, size.0 + )), err => internal_error_with_message("Failed to snapshot the working copy", err), } } diff --git a/cli/tests/test_working_copy.rs b/cli/tests/test_working_copy.rs index 461125b7f6..a7bacea343 100644 --- a/cli/tests/test_working_copy.rs +++ b/cli/tests/test_working_copy.rs @@ -25,8 +25,13 @@ fn test_snapshot_large_file() { let stderr = test_env.jj_cmd_failure(&repo_path, &["files"]); insta::assert_snapshot!(stderr, @r###" Error: Failed to snapshot the working copy - Caused by: New file $TEST_ENV/repo/large of size ~13.0B exceeds snapshot.max-new-file-size (10.0B) - Hint: Increase the value of the `snapshot.max-new-file-size` config option if you - want this file to be snapshotted. Otherwise add it to your `.gitignore` file. + The file '$TEST_ENV/repo/large' is too large to be snapshotted (13 bytes). + The maximum size allowed is 10 bytes. + Hint: This is to prevent large files from being added on accident. You can fix this error by: + - Adding the file to `.gitignore` + - Run `jj config set --repo snapshot.max-new-file-size "13B"` + This will increase the maximum file size allowed for new files, in this repository only. + - Run `jj --config-toml 'snapshot.max-new-file-size="13B"' st` + This will increase the maximum file size allowed for new files, for this command only. "###); }