diff --git a/Cargo.lock b/Cargo.lock index 3da0d8ca455..c576dbfc184 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1699,6 +1699,7 @@ dependencies = [ "pest", "pest_derive", "pollster", + "rand", "regex", "rpassword", "scm-record", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1444902a565..49f09d06519 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -58,6 +58,7 @@ once_cell = { workspace = true } pest = { workspace = true } pest_derive = { workspace = true } pollster = { workspace = true } +rand = { workspace = true } regex = { workspace = true } rpassword = { workspace = true } scm-record = { workspace = true } diff --git a/cli/tests/test_working_copy.rs b/cli/tests/test_working_copy.rs index a7bacea3436..054c15295cd 100644 --- a/cli/tests/test_working_copy.rs +++ b/cli/tests/test_working_copy.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use rand::Rng; + use crate::common::TestEnvironment; #[test] @@ -34,4 +36,22 @@ fn test_snapshot_large_file() { - 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. "###); + + // test with a larger file, using 'KB' human-readable syntax + test_env.add_config(r#"snapshot.max-new-file-size = "10KB""#); + let mut big_string = vec![0; 1024 * 11]; + rand::thread_rng().fill(&mut big_string[..]); + std::fs::write(repo_path.join("large"), big_string).unwrap(); + let stderr = test_env.jj_cmd_failure(&repo_path, &["files"]); + insta::assert_snapshot!(stderr, @r###" + Error: Failed to snapshot the working copy + The file '$TEST_ENV/repo/large' is too large to be snapshotted (11264 bytes). + The maximum size allowed is 10240 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 "11264B"` + This will increase the maximum file size allowed for new files, in this repository only. + - Run `jj --config-toml 'snapshot.max-new-file-size="11264B"' st` + This will increase the maximum file size allowed for new files, for this command only. + "###); }