| 1 | mod merkle; |
| 2 | use homedir::get_my_home; |
| 3 | use merkle::{compute_tree_for_dir, diff, hash_string}; |
| 4 | use std::{ |
| 5 | collections::HashMap, |
| 6 | fs::{self, File, OpenOptions}, |
| 7 | io::{Read, Seek, SeekFrom, Write}, |
| 8 | path::{Path, PathBuf}, |
| 9 | time::{SystemTime, UNIX_EPOCH}, |
| 10 | }; |
| 11 | |
| 12 | use self::merkle::{ObjDescription, Tree}; |
| 13 | |
| 14 | #[derive(Clone)] |
| 15 | pub struct Tag<'a> { |
| 16 | pub dir: &'a Path, |
| 17 | pub branch: &'a str, |
| 18 | pub provider_id: &'a str, |
| 19 | } |
| 20 | |
| 21 | impl<'a> Tag<'a> { |
| 22 | pub fn to_string(&self) -> String { |
| 23 | return format!( |
| 24 | "{}::{}::{}", |
| 25 | self.dir.to_str().unwrap(), |
| 26 | self.branch, |
| 27 | self.provider_id |
| 28 | ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn remove_seps_from_path(dir: &Path) -> String { |
| 33 | let mut path = String::new(); |
| 34 | for component in dir.components() { |
| 35 | path.push_str(component.as_os_str().to_str().unwrap()); |
| 36 | } |
| 37 | |
| 38 | // Remove leading slash |
| 39 | if path.starts_with('/') || path.starts_with('\\') { |
| 40 | path.remove(0); |
| 41 | } |
| 42 | path |
| 43 | } |
| 44 | |
| 45 | fn path_for_tag(tag: &Tag) -> PathBuf { |
| 46 | let mut path = get_my_home().unwrap().unwrap(); |
| 47 | path.push(".continue/index/tags"); |
| 48 | path.push(remove_seps_from_path(tag.dir)); |
| 49 | path.push(tag.branch); |
| 50 | path.push(tag.provider_id); |
| 51 | return path; |
| 52 | } |
| 53 | |
| 54 | /// Stored in ~/.continue/index/.last_sync |
| 55 | fn get_last_sync_time(tag: &Tag) -> u64 { |
| 56 | // TODO: Error handle here |
| 57 | let path = path_for_tag(tag).join(".last_sync"); |
| 58 | |
| 59 | // let mut file = File::open(path).unwrap(); |
| 60 | // let mut contents = String::new(); |
| 61 | // file.read_to_string(&mut contents).unwrap(); |
| 62 | |
| 63 | // contents.parse::<u64>().unwrap() |
| 64 | // } |
| 65 | |
| 66 | fn write_sync_time(tag: &Tag) { |
| 67 | let path = path_for_tag(tag).join(".last_sync"); |
| 68 | |
| 69 | let mut file = File::create(path).unwrap(); |
| 70 | let now = SystemTime::now() |
| 71 | .duration_since(UNIX_EPOCH) |
| 72 | .unwrap() |
| 73 | .as_secs(); |
| 74 | file.write_all(now.to_string().as_bytes()).unwrap(); |
| 75 | } |
| 76 | |
| 77 | /// Use stat to find files since last sync time |
| 78 | pub fn get_modified_files(tag: &Tag) -> Vec<PathBuf> { |
| 79 | let last_sync_time = get_last_sync_time(tag); |
| 80 | let mut modified_files = Vec::new(); |
| 81 | for entry in build_walk(tag.dir) { |
| 82 | let entry = entry.unwrap(); |
| 83 | let path = entry.path(); |
| 84 | let metadata = path.metadata().unwrap(); |
| 85 | let modified = metadata.modified().unwrap(); |
| 86 | |
| 87 | // build_walk(dir) |
| 88 | // .filter_map(|entry| { |
| 89 | // let entry = entry.unwrap(); |
| 90 | // let path = entry.path(); |
| 91 | // let metadata = path.metadata().unwrap(); |
| 92 | // let modified = metadata.modified().unwrap(); |
| 93 | |
| 94 | // if modified.duration_since(UNIX_EPOCH).unwrap().as_secs() > last_sync_time { |
| 95 | // Some(path.to_path_buf()) |
| 96 | // } else { |
| 97 | // None |
| 98 | // } |
| 99 | // }) |
| 100 | // .collect() |
| 101 | // } |
| 102 | |
| 103 | // Merkle trees are unique to directories, even if nested, but .index_cache is shared between all |
| 104 | |
| 105 | struct DiskSet { |
| 106 | file: File, |
| 107 | } |
| 108 | |
| 109 | const ITEM_SIZE: usize = 20; |
| 110 | |
| 111 | impl DiskSet { |
| 112 | pub fn new(path: &str) -> Self { |
| 113 | let path = Path::new(path); |
| 114 | if !path.exists() { |
| 115 | File::create(path).unwrap(); |
| 116 | } |
| 117 | |
| 118 | Self { |
| 119 | file: OpenOptions::new() |
| 120 | .read(true) |
| 121 | .write(true) |
| 122 | .open(path) |
| 123 | .unwrap(), |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | pub fn contains(&mut self, item: &[u8; ITEM_SIZE]) -> bool { |
| 128 | self.file.seek(SeekFrom::Start(0)).unwrap(); |
| 129 | let mut buffer = [0; ITEM_SIZE]; |
| 130 | while self.file.read_exact(&mut buffer).is_ok() { |
| 131 | if &buffer == item { |
| 132 | return true; |
| 133 | } |
| 134 | } |
| 135 | false |
| 136 | } |
| 137 | |
| 138 | pub fn add(&mut self, item: &[u8; ITEM_SIZE]) { |
| 139 | if self.contains(item) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | self.file.write_all(item).unwrap(); |
| 144 | self.file.flush().unwrap(); |
| 145 | } |
| 146 | |
| 147 | pub fn remove(&mut self, item: &[u8; ITEM_SIZE]) { |
| 148 | self.file.seek(SeekFrom::Start(0)).unwrap(); |
| 149 | let mut buffer = [0; ITEM_SIZE]; |
| 150 | let mut pos = 0; |
| 151 | let mut found = false; |
| 152 | while self.file.read_exact(&mut buffer).is_ok() { |
| 153 | if &buffer == item { |
| 154 | found = true; |
| 155 | break; |
| 156 | } |
| 157 | pos = self.file.stream_position().unwrap() as usize; |
| 158 | } |
| 159 | |
| 160 | if found { |
| 161 | // Calculate the position of the last item |
| 162 | let len = self.file.metadata().unwrap().len() as usize; |
| 163 | let last_item_pos = len - ITEM_SIZE; |
| 164 | |
| 165 | // Move the last item in the file to the position of the item we want to remove |
| 166 | self.file |
| 167 | .seek(SeekFrom::Start(last_item_pos as u64)) |
| 168 | .unwrap(); |
| 169 | self.file.read_exact(&mut buffer).unwrap(); |
| 170 | self.file.seek(SeekFrom::Start(pos as u64)).unwrap(); |
| 171 | self.file.write_all(&buffer).unwrap(); |
| 172 | |
| 173 | // Truncate the file at the position of the last item |
| 174 | self.file.set_len(last_item_pos as u64).unwrap(); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | struct IndexCache<'a> { |
| 180 | tag: Box<Tag<'a>>, |
| 181 | global_cache: DiskSet, |
| 182 | tag_cache: DiskSet, |
| 183 | } |
| 184 | |
| 185 | impl<'a> IndexCache<'a> { |
| 186 | fn index_cache_path_for_tag(tag: &Tag) -> PathBuf { |
| 187 | let mut path = path_for_tag(tag); |
| 188 | path.push(".index_cache"); |
| 189 | path |
| 190 | } |
| 191 | |
| 192 | fn rev_tags_dir(provider_id: &str) -> PathBuf { |
| 193 | let mut path = IndexCache::provider_dir(provider_id); |
| 194 | path.push("rev_tags"); |
| 195 | return path; |
| 196 | } |
| 197 | |
| 198 | fn rev_tags_path(hash: [u8; ITEM_SIZE], provider_id: &str) -> PathBuf { |
| 199 | let hash_str = hash_string(hash); |
| 200 | let mut path = IndexCache::rev_tags_dir(provider_id); |
| 201 | // Branch by 1) first two chars of hash |
| 202 | path.push(&hash_str[0..2]); |
| 203 | path |
| 204 | } |
| 205 | |
| 206 | fn tag_str(&self) -> String { |
| 207 | return self.tag.to_string(); |
| 208 | } |
| 209 | |
| 210 | fn provider_dir(provider_id: &str) -> PathBuf { |
| 211 | let mut path = get_my_home().unwrap().unwrap(); |
| 212 | path.push(".continue/index/providers"); |
| 213 | path.push(provider_id); |
| 214 | return path; |
| 215 | } |
| 216 | |
| 217 | fn new(tag: &'a Tag) -> IndexCache<'a> { |
| 218 | return IndexCache { |
| 219 | tag: Box::new(tag.clone()), |
| 220 | global_cache: DiskSet::new( |
| 221 | IndexCache::provider_dir(tag.provider_id) |
| 222 | .join(".index_cache") |
| 223 | .to_str() |
| 224 | .unwrap(), |
| 225 | ), |
| 226 | tag_cache: DiskSet::new(IndexCache::index_cache_path_for_tag(tag).to_str().unwrap()), |
| 227 | }; |
| 228 | } |
| 229 | |
| 230 | // rev_tags files are just json files with the following format: |
| 231 | // { "hash": ["tag1", "tag2", ...], ... } |
| 232 | |
| 233 | // TODO: You could add_bulk, remove_bulk if this gets slow |
| 234 | fn read_rev_tags(&self, hash: [u8; ITEM_SIZE]) -> HashMap<String, Vec<String>> { |
| 235 | let rev_tags_path = IndexCache::rev_tags_path(hash, self.tag.provider_id); |
| 236 | let mut rev_tags_file = OpenOptions::new() |
| 237 | .read(true) |
| 238 | .write(true) |
| 239 | .create(true) |
| 240 | .open(rev_tags_path) |
| 241 | .unwrap(); |
| 242 | let mut contents = String::new(); |
| 243 | rev_tags_file.read_to_string(&mut contents).unwrap(); |
| 244 | |
| 245 | serde_json::from_str(&contents).unwrap_or_default() |
| 246 | } |
| 247 | |
| 248 | fn write_rev_tags(&self, hash: [u8; ITEM_SIZE], rev_tags: HashMap<String, Vec<String>>) { |
| 249 | let rev_tags_path = IndexCache::rev_tags_path(hash, self.tag.provider_id); |
| 250 | let mut rev_tags_file = OpenOptions::new() |
| 251 | .read(true) |
| 252 | .write(true) |
| 253 | .create(true) |
| 254 | .open(rev_tags_path) |
| 255 | .unwrap(); |
| 256 | let json = serde_json::to_string(&rev_tags).unwrap(); |
| 257 | |
| 258 | // Rewrite the whole file |
| 259 | rev_tags_file.set_len(0).unwrap(); |
| 260 | rev_tags_file.seek(SeekFrom::Start(0)).unwrap(); |
| 261 | rev_tags_file.write_all(json.as_bytes()).unwrap(); |
| 262 | rev_tags_file.flush().unwrap(); |
| 263 | } |
| 264 | |
| 265 | fn add_global(&mut self, item: &ObjDescription) { |
| 266 | self.global_cache.add(&item.hash); |
| 267 | self.tag_cache.add(&item.hash); |
| 268 | |
| 269 | // Add to rev_tags |
| 270 | let mut rev_tags = Self::read_rev_tags(item.hash); |
| 271 | let tag_str = self.tag_str(); |
| 272 | let hash_str = hash_string(item.hash); |
| 273 | if !rev_tags.contains_key(hash_str.as_str()) { |
| 274 | rev_tags.insert(hash_str.clone(), Vec::new()); |
| 275 | } |
| 276 | rev_tags.get_mut(hash_str.as_str()).unwrap().push(tag_str); |
| 277 | Self::write_rev_tags(item.hash, &rev_tags); |
| 278 | } |
| 279 | |
| 280 | fn global_remove(&mut self, item: &ObjDescription) { |
| 281 | self.global_cache.remove(&item.hash); |
| 282 | self.tag_cache.remove(&item.hash); |
| 283 | |
| 284 | // Remove from rev_tags |
| 285 | let mut rev_tags = Self::read_rev_tags(item.hash); |
| 286 | let hash_str = hash_string(item.hash); |
| 287 | if rev_tags.contains_key(hash_str.as_str()) { |
| 288 | rev_tags.remove(hash_str.as_str()); |
| 289 | } |
| 290 | Self::write_rev_tags(item.hash, &rev_tags); |
| 291 | } |
| 292 | |
| 293 | fn local_remove(&mut self, item: &ObjDescription) { |
| 294 | self.tag_cache.remove(&item.hash); |
| 295 | |
| 296 | // Remove from rev_tags |
| 297 | let mut rev_tags = Self::read_rev_tags(item.hash); |
| 298 | let tag_str = self.tag_str(); |
| 299 | let hash_str = hash_string(item.hash); |
| 300 | if rev_tags.contains_key(hash_str.as_str()) { |
| 301 | let tags = rev_tags.get_mut(hash_str.as_str()).unwrap(); |
| 302 | let index = tags.iter().position(|x| *x == tag_str).unwrap(); |
| 303 | tags.remove(index); |
| 304 | if tags.is_empty() { |
| 305 | rev_tags.remove(hash_str.as_str()); |
| 306 | } |
| 307 | } |
| 308 | Self::write_rev_tags(item.hash, &rev_tags); |
| 309 | } |
| 310 | |
| 311 | fn global_contains(&mut self, hash: &[u8; ITEM_SIZE]) -> bool { |
| 312 | self.global_cache.contains(hash) |
| 313 | } |
| 314 | |
| 315 | // fn tag_contains(&mut self, hash: &[u8; ITEM_SIZE]) -> bool { |
| 316 | // self.tag_cache.contains(hash) |
| 317 | // } |
| 318 | |
| 319 | fn get_rev_tags(hash: &[u8; ITEM_SIZE]) -> Vec<String> { |
| 320 | let mut rev_tags = Self::read_rev_tags(*hash); |
| 321 | let hash_str = hash_string(*hash); |
| 322 | if rev_tags.contains_key(hash_str.as_str()) { |
| 323 | rev_tags.remove(hash_str.as_str()).unwrap() |
| 324 | } else { |
| 325 | Vec::new() |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | pub fn sync( |
| 331 | tag: &Tag, |
| 332 | ) -> Result< |
| 333 | ( |
| 334 | Vec<(String, String)>, |
| 335 | Vec<(String, String)>, |
| 336 | Vec<(String, String)>, |
| 337 | Vec<(String, String)>, |
| 338 | ), |
| 339 | Box<dyn std::error::Error>, |
| 340 | > { |
| 341 | // Make sure that the tag directory exists |
| 342 | // Create the directory and all its parent directories if they don't exist |
| 343 | fs::create_dir_all(path_for_tag(tag)).unwrap(); |
| 344 | if let Some(parent) = IndexCache::rev_tags_path([0; ITEM_SIZE], tag.provider_id).parent() { |
| 345 | fs::create_dir_all(parent).unwrap(); |
| 346 | } |
| 347 | |
| 348 | let mut tree_path = path_for_tag(tag); |
| 349 | tree_path.push("merkle_tree"); |
| 350 | |
| 351 | let old_tree = Tree::load(&tree_path).unwrap_or_default(); |
| 352 | |
| 353 | // Calculate and save new tree |
| 354 | // TODO: Use modified files to speed up calculation |
| 355 | // let modified_files = get_modified_files(dir, branch); |
| 356 | let new_tree = compute_tree_for_dir(tag.dir, None)?; |
| 357 | |
| 358 | // Update last sync time |
| 359 | write_sync_time(tag); |
| 360 | |
| 361 | // Save new tree |
| 362 | new_tree.persist(&tree_path); |
| 363 | |
| 364 | // Compute diff |
| 365 | let (add, remove) = diff(&old_tree, &new_tree); |
| 366 | |
| 367 | // Compute the four action types: compute, remove, add tag, remove tag, |
| 368 | // transform into desired format: [(path, hash), ...], |
| 369 | // and update .index_cache |
| 370 | let mut index_cache = IndexCache::new(tag); |
| 371 | |
| 372 | let mut compute: Vec<(String, String)> = Vec::new(); |
| 373 | let mut delete: Vec<(String, String)> = Vec::new(); |
| 374 | let mut add_label: Vec<(String, String)> = Vec::new(); |
| 375 | let mut remove_label: Vec<(String, String)> = Vec::new(); |
| 376 | |
| 377 | for item in add { |
| 378 | if !item.is_blob { |
| 379 | continue; |
| 380 | } |
| 381 | let path = item.path.as_str().to_string(); |
| 382 | let hash = hash_string(item.hash); |
| 383 | |
| 384 | // Need to specify between global and local contains |
| 385 | if index_cache.global_contains(&item.hash) { |
| 386 | add_label.push((path, hash)); |
| 387 | |
| 388 | // Add to local cache |
| 389 | index_cache.add_global(&item); |
| 390 | } else { |
| 391 | compute.push((path, hash)); |
| 392 | |
| 393 | // Add to global and local cache |
| 394 | index_cache.add_global(&item); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | for item in remove { |
| 399 | if !item.is_blob { |
| 400 | continue; |
| 401 | } |
| 402 | if index_cache.global_contains(&item.hash) { |
| 403 | if IndexCache::get_rev_tags(&item.hash).len() <= 1 { |
| 404 | // If it's cached only for this tag, remove it from the global cache as well |
| 405 | index_cache.global_remove(&item); |
| 406 | let hash = hash_string(item.hash); |
| 407 | let path = item.path.as_str().to_string(); |
| 408 | delete.push((path, hash)); |
| 409 | } else { |
| 410 | // Otherwise, remove label, remove from local cache |
| 411 | index_cache.local_remove(&item); |
| 412 | let hash = hash_string(item.hash); |
| 413 | let path = item.path.as_str().to_string(); |
| 414 | remove_label.push((path, hash)); |
| 415 | } |
| 416 | } else { |
| 417 | // Should never happen |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | Ok((compute, delete, add_label, remove_label)) |
| 422 | } |
| 423 | |
| 424 | #[cfg(test)] |
| 425 | mod tests { |
| 426 | use super::*; |
| 427 | use crate::{sync::merkle::ObjectHash, utils::TempDirBuilder}; |
| 428 | use std::fs::remove_file; |
| 429 | |
| 430 | #[test] |
| 431 | fn test_disk_set() { |
| 432 | let path = "testfile"; |
| 433 | let mut disk_set = DiskSet::new(path); |
| 434 | |
| 435 | let item1: ObjectHash = [1; ITEM_SIZE]; |
| 436 | let item2: ObjectHash = [20; ITEM_SIZE]; |
| 437 | let item3: ObjectHash = [30; ITEM_SIZE]; |
| 438 | |
| 439 | // Test add and contains |
| 440 | disk_set.add(&item1); |
| 441 | disk_set.add(&item2); |
| 442 | assert!(disk_set.contains(&item1)); |
| 443 | assert!(disk_set.contains(&item2)); |
| 444 | |
| 445 | // Test the exact contents of the file |
| 446 | disk_set.file.seek(SeekFrom::Start(0)).unwrap(); |
| 447 | let mut buffer = [0; ITEM_SIZE]; |
| 448 | disk_set.file.read_exact(&mut buffer).unwrap(); |
| 449 | assert_eq!(buffer, item1); |
| 450 | disk_set.file.read_exact(&mut buffer).unwrap(); |
| 451 | assert_eq!(buffer, item2); |
| 452 | |
| 453 | // Test remove |
| 454 | disk_set.remove(&item1); |
| 455 | assert!(!disk_set.contains(&item1)); |
| 456 | assert!(disk_set.contains(&item2)); |
| 457 | |
| 458 | // Test one more add |
| 459 | disk_set.add(&item3); |
| 460 | assert!(disk_set.contains(&item3)); |
| 461 | |
| 462 | // Test the length of the file |
| 463 | disk_set.file.seek(SeekFrom::Start(0)).unwrap(); |
| 464 | let mut buffer = [0; ITEM_SIZE]; |
| 465 | let mut count = 0; |
| 466 | while disk_set.file.read_exact(&mut buffer).is_ok() { |
| 467 | count += 1; |
| 468 | } |
| 469 | assert_eq!(count, 2); |
| 470 | |
| 471 | // Clean up |
| 472 | remove_file(path).unwrap(); |
| 473 | } |
| 474 | |
| 475 | #[test] |
| 476 | fn test_sync() { |
| 477 | let ti = std::time::Instant::now(); |
| 478 | let tag = Tag { |
| 479 | dir: Path::new("../"), |
| 480 | branch: "nate/pyO3", |
| 481 | provider_id: "default", |
| 482 | }; |
| 483 | let results = sync(&tag); |
| 484 | println!("Sync took {:?}", ti.elapsed()); |
| 485 | // Vast majority (90+%) of this time is spent in compute_tree_for_dir |
| 486 | } |
| 487 | |
| 488 | #[test] |
| 489 | fn test_on_vscode_extension() { |
| 490 | let results = sync(&Tag { |
| 491 | dir: Path::new("../extensions/vscode"), |
| 492 | branch: "nate/pyO3", |
| 493 | provider_id: "default", |
| 494 | }); |
| 495 | } |
| 496 | |
| 497 | #[test] |
| 498 | fn test_double_sync() { |
| 499 | let ti = std::time::Instant::now(); |
| 500 | let results = sync(&Tag { |
| 501 | dir: Path::new("../"), |
| 502 | branch: "nate/pyO3", |
| 503 | provider_id: "default", |
| 504 | }) |
| 505 | .expect("Sync failed."); |
| 506 | println!("First sync took {:?}", ti.elapsed()); |
| 507 | assert!(!results.0.is_empty()); |
| 508 | assert!(!results.1.is_empty()); |
| 509 | |
| 510 | let ti = std::time::Instant::now(); |
| 511 | let results = sync(&Tag { |
| 512 | dir: Path::new("../"), |
| 513 | branch: "nate/pyO3", |
| 514 | provider_id: "default", |
| 515 | }) |
| 516 | .expect("Sync failed"); |
| 517 | println!("Second sync took {:?}", ti.elapsed()); |
| 518 | assert_eq!(results.0.len(), 0); |
| 519 | assert_eq!(results.1.len(), 0); |
| 520 | } |
| 521 | |
| 522 | #[test] |
| 523 | fn test_sync_v3() { |
| 524 | // Create temp directory |
| 525 | let temp_dir = TempDirBuilder::new() |
| 526 | .add("dir1/file1.txt", "File 1") |
| 527 | .add("dir1/file2.txt", "File 2") |
| 528 | .add("dir2/file3.txt", "File 3") |
| 529 | .add("dir2/subdir/continue.py", "[continue for i in range(10)]") |
| 530 | .add("__init__.py", "a = 5") |
| 531 | .create(); |
| 532 | |
| 533 | let tag = &Tag { |
| 534 | dir: temp_dir.path(), |
| 535 | branch: "BRANCH", |
| 536 | provider_id: "default", |
| 537 | }; |
| 538 | // Sync once |
| 539 | sync(&tag).expect("Sync failed."); |
| 540 | |
| 541 | // Make changes |
| 542 | let mut file = File::create(temp_dir.path().join("dir1/file1.txt")).unwrap(); |
| 543 | file.write_all(b"File 1 changed").unwrap(); |
| 544 | let mut file = File::create(temp_dir.path().join("dir2/file3.txt")).unwrap(); |
| 545 | file.write_all(b"File 3 changed").unwrap(); |
| 546 | |
| 547 | // Sync again |
| 548 | let results = sync(tag).expect("Sync failed."); |
| 549 | |
| 550 | // Check results |
| 551 | assert_eq!(results.0.len(), 2); |
| 552 | assert_eq!(results.1.len(), 2); |
| 553 | assert_eq!(results.2.len(), 0); |
| 554 | assert_eq!(results.3.len(), 0); |
| 555 | |
| 556 | // Start a new branch |
| 557 | |
| 558 | let tag2 = &Tag { |
| 559 | dir: temp_dir.path(), |
| 560 | branch: "BRANCH2", |
| 561 | provider_id: "default", |
| 562 | }; |
| 563 | // Sync again |
| 564 | let results = sync(tag2).expect("Sync failed."); |
| 565 | |
| 566 | // Check results |
| 567 | assert_eq!(results.0.len(), 0); |
| 568 | assert_eq!(results.1.len(), 0); |
| 569 | assert_eq!(results.2.len(), 5); |
| 570 | assert_eq!(results.3.len(), 0); |
| 571 | |
| 572 | // Delete a file in this new branch |
| 573 | remove_file(temp_dir.path().join("dir1/file2.txt")).unwrap(); |
| 574 | |
| 575 | // Sync again |
| 576 | let results = sync(tag2).expect("Sync failed."); |
| 577 | |
| 578 | // Check results |
| 579 | assert_eq!(results.0.len(), 0); |
| 580 | assert_eq!(results.1.len(), 0); |
| 581 | assert_eq!(results.2.len(), 0); |
| 582 | assert_eq!(results.3.len(), 1); |
| 583 | } |
| 584 | } |