mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-07 04:51:45 +00:00
working_copy: remove untrack()
now that we have more flexible reset()
This commit is contained in:
parent
4b91ad408c
commit
8c97fdf5d6
2 changed files with 1 additions and 97 deletions
|
@ -38,7 +38,7 @@ use crate::commit::Commit;
|
||||||
use crate::conflicts::{materialize_conflict, update_conflict_from_content};
|
use crate::conflicts::{materialize_conflict, update_conflict_from_content};
|
||||||
use crate::gitignore::GitIgnoreFile;
|
use crate::gitignore::GitIgnoreFile;
|
||||||
use crate::lock::FileLock;
|
use crate::lock::FileLock;
|
||||||
use crate::matchers::{EverythingMatcher, Matcher};
|
use crate::matchers::EverythingMatcher;
|
||||||
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin};
|
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin};
|
||||||
use crate::store::Store;
|
use crate::store::Store;
|
||||||
use crate::tree::{Diff, Tree};
|
use crate::tree::{Diff, Tree};
|
||||||
|
@ -199,16 +199,6 @@ pub enum ResetError {
|
||||||
InternalBackendError(BackendError),
|
InternalBackendError(BackendError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error, PartialEq, Eq)]
|
|
||||||
pub enum UntrackError {
|
|
||||||
// The current checkout was deleted, maybe by an overly aggressive GC that happened while
|
|
||||||
// the current process was running.
|
|
||||||
#[error("Current checkout not found")]
|
|
||||||
SourceNotFound,
|
|
||||||
#[error("Internal error: {0:?}")]
|
|
||||||
InternalBackendError(BackendError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TreeState {
|
impl TreeState {
|
||||||
pub fn current_tree_id(&self) -> &TreeId {
|
pub fn current_tree_id(&self) -> &TreeId {
|
||||||
&self.tree_id
|
&self.tree_id
|
||||||
|
@ -721,24 +711,6 @@ impl TreeState {
|
||||||
self.tree_id = new_tree.id().clone();
|
self.tree_id = new_tree.id().clone();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn untrack(&mut self, matcher: &dyn Matcher) -> Result<TreeId, UntrackError> {
|
|
||||||
let tree = self
|
|
||||||
.store
|
|
||||||
.get_tree(&RepoPath::root(), &self.tree_id)
|
|
||||||
.map_err(|err| match err {
|
|
||||||
BackendError::NotFound => UntrackError::SourceNotFound,
|
|
||||||
other => UntrackError::InternalBackendError(other),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut tree_builder = self.store.tree_builder(self.tree_id.clone());
|
|
||||||
for (path, _value) in tree.entries_matching(matcher) {
|
|
||||||
self.file_states.remove(&path);
|
|
||||||
tree_builder.remove(path);
|
|
||||||
}
|
|
||||||
self.tree_id = tree_builder.write_tree();
|
|
||||||
Ok(self.tree_id.clone())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WorkingCopy {
|
pub struct WorkingCopy {
|
||||||
|
@ -921,10 +893,6 @@ impl LockedWorkingCopy<'_> {
|
||||||
self.wc.tree_state().as_mut().unwrap().reset(new_tree)
|
self.wc.tree_state().as_mut().unwrap().reset(new_tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn untrack(&mut self, matcher: &dyn Matcher) -> Result<TreeId, UntrackError> {
|
|
||||||
self.wc.tree_state().as_mut().unwrap().untrack(matcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn finish(mut self, commit_id: CommitId) {
|
pub fn finish(mut self, commit_id: CommitId) {
|
||||||
self.wc.tree_state().as_mut().unwrap().save();
|
self.wc.tree_state().as_mut().unwrap().save();
|
||||||
self.wc.commit_id.replace(Some(commit_id));
|
self.wc.commit_id.replace(Some(commit_id));
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -22,7 +21,6 @@ use std::sync::Arc;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use jujutsu_lib::backend::{Conflict, ConflictPart, TreeValue};
|
use jujutsu_lib::backend::{Conflict, ConflictPart, TreeValue};
|
||||||
use jujutsu_lib::commit_builder::CommitBuilder;
|
use jujutsu_lib::commit_builder::CommitBuilder;
|
||||||
use jujutsu_lib::matchers::FilesMatcher;
|
|
||||||
use jujutsu_lib::repo::ReadonlyRepo;
|
use jujutsu_lib::repo::ReadonlyRepo;
|
||||||
use jujutsu_lib::repo_path::{RepoPath, RepoPathComponent};
|
use jujutsu_lib::repo_path::{RepoPath, RepoPathComponent};
|
||||||
use jujutsu_lib::settings::UserSettings;
|
use jujutsu_lib::settings::UserSettings;
|
||||||
|
@ -371,68 +369,6 @@ fn test_reset() {
|
||||||
locked_wc.discard();
|
locked_wc.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_untrack() {
|
|
||||||
let settings = testutils::user_settings();
|
|
||||||
let mut test_workspace = testutils::init_repo(&settings, false);
|
|
||||||
let repo = &test_workspace.repo;
|
|
||||||
let workspace_root = test_workspace.workspace.workspace_root().clone();
|
|
||||||
|
|
||||||
let wanted_path = RepoPath::from_internal_string("wanted");
|
|
||||||
let unwanted_path = RepoPath::from_internal_string("unwanted");
|
|
||||||
let gitignore_path = RepoPath::from_internal_string(".gitignore");
|
|
||||||
|
|
||||||
// First create a commit where one of the files is unwanted.
|
|
||||||
let initial_tree = testutils::create_tree(
|
|
||||||
repo,
|
|
||||||
&[
|
|
||||||
(&wanted_path, "code"),
|
|
||||||
(&unwanted_path, "garbage"),
|
|
||||||
(&gitignore_path, "unwanted\n"),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
let mut tx = repo.start_transaction("test");
|
|
||||||
let initial_commit = CommitBuilder::for_open_commit(
|
|
||||||
&settings,
|
|
||||||
repo.store(),
|
|
||||||
repo.store().root_commit_id().clone(),
|
|
||||||
initial_tree.id().clone(),
|
|
||||||
)
|
|
||||||
.write_to_repo(tx.mut_repo());
|
|
||||||
let repo = tx.commit();
|
|
||||||
let wc = test_workspace.workspace.working_copy_mut();
|
|
||||||
wc.check_out(initial_commit.clone()).unwrap();
|
|
||||||
|
|
||||||
// Now we untrack the file called "unwanted"
|
|
||||||
let mut tx = repo.start_transaction("test");
|
|
||||||
let matcher = FilesMatcher::new(HashSet::from([unwanted_path.clone()]));
|
|
||||||
let mut locked_wc = wc.start_mutation();
|
|
||||||
let new_tree_id = locked_wc.untrack(&matcher).unwrap();
|
|
||||||
let new_commit = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial_commit)
|
|
||||||
.set_tree(new_tree_id)
|
|
||||||
.write_to_repo(tx.mut_repo());
|
|
||||||
locked_wc.finish(new_commit.id().clone());
|
|
||||||
tx.commit();
|
|
||||||
|
|
||||||
// The file should still exist in the working copy.
|
|
||||||
assert!(unwanted_path.to_fs_path(&workspace_root).is_file());
|
|
||||||
|
|
||||||
// It should not be in the new tree.
|
|
||||||
let tracked_paths = new_commit
|
|
||||||
.tree()
|
|
||||||
.entries()
|
|
||||||
.map(|(path, _)| path)
|
|
||||||
.collect_vec();
|
|
||||||
assert_eq!(tracked_paths, vec![gitignore_path, wanted_path]);
|
|
||||||
|
|
||||||
// It should not get re-added if we write a new tree since we also added it
|
|
||||||
// to the .gitignore file.
|
|
||||||
let mut locked_wc = wc.start_mutation();
|
|
||||||
let new_tree_id = locked_wc.write_tree();
|
|
||||||
assert_eq!(new_tree_id, *new_commit.tree().id());
|
|
||||||
locked_wc.discard();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test_case(false ; "local backend")]
|
#[test_case(false ; "local backend")]
|
||||||
#[test_case(true ; "git backend")]
|
#[test_case(true ; "git backend")]
|
||||||
fn test_commit_racy_timestamps(use_git: bool) {
|
fn test_commit_racy_timestamps(use_git: bool) {
|
||||||
|
|
Loading…
Reference in a new issue