diff --git a/lib/src/repo_path.rs b/lib/src/repo_path.rs index 0950e39e4..7e37d7e3d 100644 --- a/lib/src/repo_path.rs +++ b/lib/src/repo_path.rs @@ -64,7 +64,7 @@ pub struct RepoPath { impl Debug for RepoPath { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - f.write_fmt(format_args!("{:?}", &self.to_internal_string())) + f.write_fmt(format_args!("{:?}", &self.to_internal_file_string())) } } @@ -84,8 +84,8 @@ impl RepoPath { /// The full string form used internally, not for presenting to users (where /// we may want to use the platform's separator). - pub fn to_internal_string(&self) -> String { - self.dir.to_internal_string() + self.basename.value() + pub fn to_internal_file_string(&self) -> String { + self.dir.to_internal_dir_string() + self.basename.value() } pub fn to_dir_repo_path(&self) -> DirRepoPath { @@ -151,7 +151,7 @@ pub struct DirRepoPath { impl Debug for DirRepoPath { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - f.write_fmt(format_args!("{:?}", &self.to_internal_string())) + f.write_fmt(format_args!("{:?}", &self.to_internal_dir_string())) } } @@ -166,7 +166,7 @@ impl DirRepoPath { /// The full string form used internally, not for presenting to users (where /// we may want to use the platform's separator). - pub fn to_internal_string(&self) -> String { + pub fn to_internal_dir_string(&self) -> String { let mut result = String::new(); for component in &self.value { result.push_str(component.value()); @@ -272,14 +272,17 @@ mod tests { #[test] fn test_value() { - assert_eq!(RepoPath::root().to_internal_string(), ""); - assert_eq!(RepoPath::from("dir").to_internal_string(), "dir"); - assert_eq!(RepoPath::from("file").to_internal_string(), "file"); - assert_eq!(RepoPath::from("dir/file").to_internal_string(), "dir/file"); - assert_eq!(DirRepoPath::root().to_internal_string(), ""); - assert_eq!(DirRepoPath::from("dir/").to_internal_string(), "dir/"); + assert_eq!(RepoPath::root().to_internal_file_string(), ""); + assert_eq!(RepoPath::from("dir").to_internal_file_string(), "dir"); + assert_eq!(RepoPath::from("file").to_internal_file_string(), "file"); assert_eq!( - DirRepoPath::from("dir/subdir/").to_internal_string(), + RepoPath::from("dir/file").to_internal_file_string(), + "dir/file" + ); + assert_eq!(DirRepoPath::root().to_internal_dir_string(), ""); + assert_eq!(DirRepoPath::from("dir/").to_internal_dir_string(), "dir/"); + assert_eq!( + DirRepoPath::from("dir/subdir/").to_internal_dir_string(), "dir/subdir/" ); } diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 8efda0d00..0d75ed3fc 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -229,9 +229,10 @@ impl TreeState { let mut proto = crate::protos::working_copy::TreeState::new(); proto.tree_id = self.tree_id.0.clone(); for (file, file_state) in &self.file_states { - proto - .file_states - .insert(file.to_internal_string(), file_state_to_proto(file_state)); + proto.file_states.insert( + file.to_internal_file_string(), + file_state_to_proto(file_state), + ); } let mut temp_file = NamedTempFile::new_in(&self.state_path).unwrap(); @@ -332,7 +333,7 @@ impl TreeState { let (dir, disk_dir, git_ignore) = work.pop().unwrap(); let git_ignore = TreeState::try_chain_gitignore( &git_ignore, - &dir.to_internal_string(), + &dir.to_internal_dir_string(), disk_dir.join(".gitignore"), ); for maybe_entry in disk_dir.read_dir().unwrap() { @@ -345,7 +346,7 @@ impl TreeState { } if file_type.is_dir() { let subdir = dir.join(&DirRepoPathComponent::from(name)); - if git_ignore.matches_all_files_in(&subdir.to_internal_string()) { + if git_ignore.matches_all_files_in(&subdir.to_internal_dir_string()) { // If the whole directory is ignored, skip it unless we're already tracking // some file in it. TODO: This is pretty ugly... Also, we should // optimize it to check exactly the already-tracked files (we know that @@ -378,7 +379,7 @@ impl TreeState { match self.file_states.get(&file) { None => { // untracked - if git_ignore.matches_file(&file.to_internal_string()) { + if git_ignore.matches_file(&file.to_internal_file_string()) { continue; } clean = false;