diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 9590b4c156..a43c4912c9 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -2575,24 +2575,14 @@ pub fn print_snapshot_stats( let ui_path = path_converter.format_file_path(path); let message = match reason { UntrackedReason::FileTooLarge { size, max_size } => { - // if the size difference is < 1KiB, then show exact bytes. - // otherwise, show in human-readable form; this avoids weird cases - // where a file is 400 bytes too large but the error says something + // Show both exact and human bytes sizes to avoid something // like '1.0MiB, maximum size allowed is ~1.0MiB' - let size_diff = size - max_size; - if size_diff <= 1024 { - format!( - "{size_diff} bytes too large; the maximum size allowed is {max_size} \ - bytes ({max_size_approx})", - max_size_approx = HumanByteSize(*max_size) - ) - } else { - format!( - "{size}; the maximum size allowed is ~{max_size}", - size = HumanByteSize(*size), - max_size = HumanByteSize(*max_size) - ) - } + let size_approx = HumanByteSize(*size); + let max_size_approx = HumanByteSize(*max_size); + format!( + "{size_approx} ({size} bytes); the maximum size allowed is \ + {max_size_approx} ({max_size} bytes)", + ) } }; writeln!(formatter, " {ui_path}: {message}")?; diff --git a/cli/tests/test_working_copy.rs b/cli/tests/test_working_copy.rs index 92d243fe94..dc2acccb20 100644 --- a/cli/tests/test_working_copy.rs +++ b/cli/tests/test_working_copy.rs @@ -31,7 +31,7 @@ fn test_snapshot_large_file() { insta::assert_snapshot!(stdout, @"empty"); insta::assert_snapshot!(stderr, @r" Warning: Refused to snapshot some files: - large: 3 bytes too large; the maximum size allowed is 10 bytes (10.0B) + large: 13.0B (13 bytes); the maximum size allowed is 10.0B (10 bytes) Hint: This is to prevent large files from being added by accident. You can fix this by: - Adding the file to `.gitignore` - Run `jj config set --repo snapshot.max-new-file-size 13` @@ -48,7 +48,7 @@ fn test_snapshot_large_file() { insta::assert_snapshot!(stdout, @"empty"); insta::assert_snapshot!(stderr, @r" Warning: Refused to snapshot some files: - large: 1024 bytes too large; the maximum size allowed is 10240 bytes (10.0KiB) + large: 11.0KiB (11264 bytes); the maximum size allowed is 10.0KiB (10240 bytes) Hint: This is to prevent large files from being added by accident. You can fix this by: - Adding the file to `.gitignore` - Run `jj config set --repo snapshot.max-new-file-size 11264` @@ -97,7 +97,7 @@ fn test_snapshot_large_file_restore() { test_env.jj_cmd_ok(&repo_path, &["restore", "--from=description(committed)"]); insta::assert_snapshot!(stderr, @r" Warning: Refused to snapshot some files: - file: 3 bytes too large; the maximum size allowed is 10 bytes (10.0B) + file: 13.0B (13 bytes); the maximum size allowed is 10.0B (10 bytes) Hint: This is to prevent large files from being added by accident. You can fix this by: - Adding the file to `.gitignore` - Run `jj config set --repo snapshot.max-new-file-size 13`