2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-03-02 06:57:28 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-04-02 16:45:02 +00:00
|
|
|
use crate::common::TestEnvironment;
|
2022-03-30 17:47:11 +00:00
|
|
|
|
|
|
|
pub mod common;
|
2022-03-02 06:57:28 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_untrack() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-01-26 19:26:18 +00:00
|
|
|
test_env.add_config(r#"ui.allow-init-native = true"#);
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "initial").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file1.bak"), "initial").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2.bak"), "initial").unwrap();
|
|
|
|
let target_dir = repo_path.join("target");
|
|
|
|
std::fs::create_dir(&target_dir).unwrap();
|
|
|
|
std::fs::write(target_dir.join("file2"), "initial").unwrap();
|
|
|
|
std::fs::write(target_dir.join("file3"), "initial").unwrap();
|
|
|
|
|
|
|
|
// Run a command so all the files get tracked, then add "*.bak" to the ignore
|
|
|
|
// patterns
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["st"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
std::fs::write(repo_path.join(".gitignore"), "*.bak\n").unwrap();
|
2022-03-26 21:06:48 +00:00
|
|
|
let files_before = test_env.jj_cmd_success(&repo_path, &["files"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
|
2022-04-20 06:05:00 +00:00
|
|
|
// Errors out when not run at the head operation
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "--at-op", "@-"]);
|
2022-11-18 20:50:39 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2022-11-12 23:28:32 +00:00
|
|
|
Error: This command must be able to update the working copy.
|
|
|
|
Hint: Don't use --at-op.
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-04-09 16:20:00 +00:00
|
|
|
// Errors out when no path is specified
|
2022-11-18 20:50:39 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["untrack"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
error: The following required arguments were not provided:
|
|
|
|
<PATHS>...
|
|
|
|
|
|
|
|
Usage: jj untrack <PATHS>...
|
|
|
|
|
|
|
|
For more information try '--help'
|
|
|
|
"###);
|
2022-03-02 06:57:28 +00:00
|
|
|
// Errors out when a specified file is not ignored
|
2022-04-07 06:25:01 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "file1.bak"]);
|
2022-11-12 23:48:25 +00:00
|
|
|
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.
|
|
|
|
"###);
|
2022-03-26 21:06:48 +00:00
|
|
|
let files_after = test_env.jj_cmd_success(&repo_path, &["files"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
// There should be no changes to the state when there was an error
|
|
|
|
assert_eq!(files_after, files_before);
|
|
|
|
|
|
|
|
// Can untrack a single file
|
|
|
|
assert!(files_before.contains("file1.bak\n"));
|
2022-03-26 21:06:48 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["untrack", "file1.bak"]);
|
|
|
|
assert_eq!(stdout, "");
|
|
|
|
let files_after = test_env.jj_cmd_success(&repo_path, &["files"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
// The file is no longer tracked
|
|
|
|
assert!(!files_after.contains("file1.bak"));
|
|
|
|
// Other files that match the ignore pattern are not untracked
|
|
|
|
assert!(files_after.contains("file2.bak"));
|
|
|
|
// The files still exist on disk
|
|
|
|
assert!(repo_path.join("file1.bak").exists());
|
|
|
|
assert!(repo_path.join("file2.bak").exists());
|
|
|
|
|
|
|
|
// Errors out when multiple specified files are not ignored
|
2022-04-07 06:25:01 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "target"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
assert_eq!(
|
2022-04-07 06:25:01 +00:00
|
|
|
stderr,
|
2022-03-02 06:57:28 +00:00
|
|
|
format!(
|
2022-11-12 23:48:25 +00:00
|
|
|
"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",
|
2022-03-02 06:57:28 +00:00
|
|
|
PathBuf::from("target").join("file2").display()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Can untrack after adding to ignore patterns
|
|
|
|
std::fs::write(repo_path.join(".gitignore"), ".bak\ntarget/\n").unwrap();
|
2022-03-26 21:06:48 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["untrack", "target"]);
|
|
|
|
assert_eq!(stdout, "");
|
|
|
|
let files_after = test_env.jj_cmd_success(&repo_path, &["files"]);
|
2022-03-02 06:57:28 +00:00
|
|
|
assert!(!files_after.contains("target"));
|
|
|
|
}
|
2022-02-06 23:10:50 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_untrack_sparse() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-01-26 19:26:18 +00:00
|
|
|
test_env.add_config(r#"ui.allow-init-native = true"#);
|
2022-02-06 23:10:50 +00:00
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "contents").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "contents").unwrap();
|
|
|
|
|
|
|
|
// When untracking a file that's not included in the sparse working copy, it
|
|
|
|
// doesn't need to be ignored (because it won't be automatically added
|
|
|
|
// back).
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["files"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
file1
|
|
|
|
file2
|
|
|
|
"###);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["sparse", "--clear", "--add", "file1"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["untrack", "file2"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["files"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
file1
|
|
|
|
"###);
|
2022-02-06 23:10:50 +00:00
|
|
|
}
|