liboxen 0.50.1

Oxen is a fast, unstructured data version control, to help version large machine learning datasets written in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
//! # oxen status
//!
//! Check which files have been modified, added, or removed,
//! and which files are staged for commit.
//!

use std::path::Path;

use crate::core;
use crate::core::versions::MinOxenVersion;
use crate::error::OxenError;
use crate::model::staged_data::StagedDataOpts;
use crate::model::{LocalRepository, StagedData};

/// # oxen status
///
/// Get status of files in repository, returns what files are tracked,
/// added, untracked, etc
///
/// Empty Repository:
///
/// ```ignore
/// use liboxen::repositories;
///
/// let base_dir = Path::new("repo_dir_status_1");
/// // Initialize empty repo
/// let repo = repositories::init(&base_dir)?;
/// // Get status on repo
/// let status = repositories::status(&repo).await?;
/// assert!(status.is_clean());
/// ```
///
/// Repository with files
/// ```ignore
/// use liboxen::repositories;
/// use liboxen::util;
///
/// let base_dir = Path::new("repo_dir_status_2");
/// // Initialize empty repo
/// let repo = repositories::init(&base_dir)?;
///
/// // Write file to disk
/// let hello_file = base_dir.join("hello.txt");
/// util::fs::write_to_path(&hello_file, "Hello World");
///
/// // Get status on repo
/// let status = repositories::status(&repo).await?;
/// assert_eq!(status.untracked_files.len(), 1);
/// ```
pub async fn status(repo: &LocalRepository) -> Result<StagedData, OxenError> {
    match repo.min_version() {
        MinOxenVersion::V0_10_0 => panic!("v0.10.0 no longer supported"),
        _ => core::v_latest::status::status(repo).await,
    }
}

pub async fn status_from_opts(
    repo: &LocalRepository,
    opts: &StagedDataOpts,
) -> Result<StagedData, OxenError> {
    match repo.min_version() {
        MinOxenVersion::V0_10_0 => panic!("v10 not supported"),
        _ => core::v_latest::status::status_from_opts(repo, opts).await,
    }
}

pub async fn status_from_dir(
    repo: &LocalRepository,
    dir: impl AsRef<Path>,
) -> Result<StagedData, OxenError> {
    match repo.min_version() {
        MinOxenVersion::V0_10_0 => panic!("v0.10.0 no longer supported"),
        _ => core::v_latest::status::status_from_dir(repo, dir).await,
    }
}

#[cfg(test)]
mod tests {
    use crate::error::OxenError;
    use crate::model::StagedEntryStatus;
    use crate::model::staged_data::StagedDataOpts;
    use crate::opts::RestoreOpts;
    use crate::opts::RmOpts;
    use crate::repositories;
    use crate::test;

    use crate::util;

    use std::collections::HashSet;
    use std::path::Path;
    use std::path::PathBuf;

    #[tokio::test]
    async fn test_command_status_empty() -> Result<(), OxenError> {
        test::run_empty_local_repo_test_async(|repo| async move {
            let repo_status = repositories::status(&repo).await?;

            assert_eq!(repo_status.staged_dirs.len(), 0);
            assert_eq!(repo_status.staged_files.len(), 0);
            assert_eq!(repo_status.untracked_files.len(), 0);
            assert_eq!(repo_status.untracked_dirs.len(), 0);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    /// Regression: a file whose working copy differs from HEAD AND whose HEAD-expected
    /// blob is missing from the local version store should be reported as "unrestorable",
    /// not "modified". The two have different remediation paths (`oxen restore` vs.
    /// `oxen fetch --missing-files`); status used to lump them together, leaving users
    /// (Kaga, in the Nex stuck-pull saga) running restore in a loop while it silently
    /// no-op'd.
    async fn test_status_distinguishes_unrestorable_from_modified() -> Result<(), OxenError> {
        test::run_empty_local_repo_test_async(|repo| async move {
            let path = repo.path.join("hello.txt");
            util::fs::write_to_path(&path, "Hello World")?;
            repositories::add(&repo, &path).await?;
            let commit = repositories::commit(&repo, "Add hello.txt")?;

            // Drift the working copy.
            util::fs::write_to_path(&path, "drifted")?;

            // Sanity: status flags it as plain `modified` while the blob is still in
            // the local version store.
            let status_before = repositories::status(&repo).await?;
            assert!(
                status_before
                    .modified_files
                    .iter()
                    .any(|p| p.ends_with("hello.txt"))
            );
            assert!(status_before.unrestorable_files.is_empty());

            // Wipe the blob HEAD expects for hello.txt. After this, `oxen restore` would
            // hit `RestoreFailed` / `VersionStoreDataMissing`.
            let head_node = repositories::tree::get_node_by_path(&repo, &commit, "hello.txt")?
                .expect("hello.txt must be in HEAD's tree");
            let blob_hash = head_node.hash.to_string();
            let version_store = repo.version_store();
            let blob_path = version_store.get_version_path(&blob_hash).await?;
            assert!(blob_path.exists());
            util::fs::remove_file(&*blob_path)?;

            let status_after = repositories::status(&repo).await?;
            assert!(
                status_after
                    .unrestorable_files
                    .iter()
                    .any(|p| p.ends_with("hello.txt")),
                "expected hello.txt under unrestorable_files, got: {:?}",
                status_after.unrestorable_files
            );
            assert!(
                !status_after
                    .modified_files
                    .iter()
                    .any(|p| p.ends_with("hello.txt")),
                "expected hello.txt NOT under modified_files (it's unrestorable), got: {:?}",
                status_after.modified_files
            );
            // is_clean and has_modified_entries should account for unrestorable files
            // the same as modified ones.
            assert!(!status_after.is_clean());
            assert!(status_after.has_modified_entries());

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_status_nothing_staged_full_directory() -> Result<(), OxenError> {
        test::run_training_data_repo_test_no_commits_async(|repo| async move {
            let repo_status = repositories::status(&repo).await?;

            assert_eq!(repo_status.staged_dirs.len(), 0);
            assert_eq!(repo_status.staged_files.len(), 0);
            // README.md
            // labels.txt
            // prompts.jsonl
            // LICENSE
            assert_eq!(repo_status.untracked_files.len(), 4);
            // train/
            // test/
            // nlp/
            // large_files/
            // annotations/
            assert_eq!(repo_status.untracked_dirs.len(), 5);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_add_one_file_top_level() -> Result<(), OxenError> {
        test::run_training_data_repo_test_no_commits_async(|repo| async move {
            repositories::add(&repo, repo.path.join(Path::new("labels.txt"))).await?;

            let repo_status = repositories::status(&repo).await?;
            repo_status.print();

            // TODO: v0_10_0 logic should have no dirs staged
            // root dir should be staged
            assert_eq!(repo_status.staged_dirs.len(), 1);
            // labels.txt
            assert_eq!(repo_status.staged_files.len(), 1);
            // README.md
            // prompts.jsonl
            // LICENSE
            assert_eq!(repo_status.untracked_files.len(), 3);
            // train/
            // test/
            // nlp/
            // large_files/
            // annotations/
            assert_eq!(repo_status.untracked_dirs.len(), 5);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_status_shows_intermediate_directory_if_file_added()
    -> Result<(), OxenError> {
        test::run_training_data_repo_test_no_commits_async(|repo| async move {
            // Add a deep file
            repositories::add(
                &repo,
                repo.path.join(Path::new("annotations/train/one_shot.csv")),
            )
            .await?;

            // Make sure that we now see the full annotations/train/ directory
            let repo_status = repositories::status(&repo).await?;
            repo_status.print();

            // annotations/
            assert_eq!(repo_status.staged_dirs.len(), 1);
            // annotations/train/one_shot.csv
            assert_eq!(repo_status.staged_files.len(), 1);
            // annotations/test/
            // train/
            // large_files/
            // test/
            // nlp/
            assert_eq!(repo_status.untracked_dirs.len(), 5);
            // README.md
            // labels.txt
            // prompts.jsonl
            // LICENSE
            // annotations/README.md
            // annotations/train/two_shot.csv
            // annotations/train/annotations.txt
            // annotations/train/bounding_box.csv
            assert_eq!(repo_status.untracked_files.len(), 8);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_modified_files_status_with_search_paths() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Modify a deep file
            let one_shot_relative_path = Path::new("annotations/train/one_shot.csv");
            let one_shot_path = repo.path.join(one_shot_relative_path);
            test::modify_txt_file(&one_shot_path, "new one shot coming in hot")?;

            // Modify a shallow file
            let labels_path = repo.path.join(Path::new("labels.txt"));
            test::modify_txt_file(&labels_path, "new labels coming in hot")?;

            let opts =
                StagedDataOpts::from_paths(&[repo.path.join(Path::new("annotations/train"))]);

            let repo_status = repositories::status::status_from_opts(&repo, &opts).await?;
            repo_status.print();

            // Make sure that we only see the modified files
            assert_eq!(repo_status.staged_dirs.len(), 0);
            assert_eq!(repo_status.staged_files.len(), 0);
            assert_eq!(repo_status.untracked_files.len(), 0);
            assert_eq!(repo_status.untracked_dirs.len(), 0);

            // We should only see the modified file in the annotations/train/ directory
            assert_eq!(repo_status.modified_files.len(), 1);
            assert!(
                repo_status
                    .modified_files
                    .contains(&one_shot_relative_path.to_path_buf())
            );

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_modified_files_status_with_file_search_paths() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Modify a deep file
            let one_shot_relative_path = Path::new("annotations/train/one_shot.csv");
            let one_shot_path = repo.path.join(one_shot_relative_path);
            test::modify_txt_file(&one_shot_path, "new one shot coming in hot")?;

            // Modify a shallow file
            let labels_path = repo.path.join(Path::new("labels.txt"));
            test::modify_txt_file(&labels_path, "new labels coming in hot")?;

            let opts = StagedDataOpts::from_paths(&[repo
                .path
                .join(Path::new("annotations/train/one_shot.csv"))]);

            let repo_status = repositories::status::status_from_opts(&repo, &opts).await?;
            repo_status.print();

            // Make sure that we only see the modified files
            assert_eq!(repo_status.staged_dirs.len(), 0);
            assert_eq!(repo_status.staged_files.len(), 0);
            assert_eq!(repo_status.untracked_files.len(), 0);
            assert_eq!(repo_status.untracked_dirs.len(), 0);

            // We should only see the modified file in the annotations/train/ directory
            assert_eq!(repo_status.modified_files.len(), 1);
            assert!(
                repo_status
                    .modified_files
                    .contains(&one_shot_relative_path.to_path_buf())
            );

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_ignore_directory_with_modified_files() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Modify a deep file
            let one_shot_relative_path = Path::new("annotations/train/one_shot.csv");
            let one_shot_path = repo.path.join(one_shot_relative_path);
            test::modify_txt_file(&one_shot_path, "new one shot coming in hot")?;

            // Modify a shallow file
            let labels_relative_path = Path::new("labels.txt");
            let labels_path = repo.path.join(labels_relative_path);
            test::modify_txt_file(&labels_path, "new labels coming in hot")?;

            let opts = StagedDataOpts {
                ignore: Some(HashSet::from([repo.path.join(Path::new("annotations"))])),
                ..Default::default()
            };

            let repo_status = repositories::status::status_from_opts(&repo, &opts).await?;
            repo_status.print();

            // Make sure that we only see the modified files
            assert_eq!(repo_status.staged_dirs.len(), 0);
            assert_eq!(repo_status.staged_files.len(), 0);
            assert_eq!(repo_status.untracked_files.len(), 0);
            assert_eq!(repo_status.untracked_dirs.len(), 0);

            // We should only see the modified file in the annotations/train/ directory
            assert_eq!(repo_status.modified_files.len(), 1);
            assert!(
                repo_status
                    .modified_files
                    .contains(&labels_relative_path.to_path_buf())
            );

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_added_files_status_with_search_paths() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Add a deep file
            let one_shot_relative_path = Path::new("annotations/train/one_shot.csv");
            let one_shot_path = repo.path.join(one_shot_relative_path);
            test::modify_txt_file(&one_shot_path, "new one shot coming in hot")?;

            repositories::add(&repo, &one_shot_path).await?;

            // Modify a deep file
            let two_shot_relative_path = Path::new("annotations/train/two_shot.csv");
            let two_shot_path = repo.path.join(two_shot_relative_path);
            test::modify_txt_file(&two_shot_path, "new two shot coming in hot")?;

            // Write an untracked file
            let untracked_relative_path = Path::new("untracked.txt");
            let untracked_path = repo.path.join(untracked_relative_path);
            test::modify_txt_file(&untracked_path, "I'm sneaking in there untracked")?;

            let opts =
                StagedDataOpts::from_paths(&[repo.path.join(Path::new("annotations/train"))]);

            let repo_status = repositories::status::status_from_opts(&repo, &opts).await?;
            repo_status.print();

            // Make sure that we only see the modified files
            assert_eq!(repo_status.staged_dirs.len(), 1);
            assert_eq!(repo_status.staged_files.len(), 1);
            assert_eq!(repo_status.untracked_files.len(), 0);
            assert_eq!(repo_status.untracked_dirs.len(), 0);

            // We should only see the modified file in the annotations/train/ directory
            assert_eq!(repo_status.modified_files.len(), 1);
            assert!(
                repo_status
                    .modified_files
                    .contains(&two_shot_relative_path.to_path_buf())
            );

            // Make sure we can see the staged file
            assert_eq!(repo_status.staged_files.len(), 1);
            assert!(
                repo_status
                    .staged_files
                    .contains_key(&one_shot_relative_path.to_path_buf())
            );

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_commit_nothing_staged() -> Result<(), OxenError> {
        test::run_empty_local_repo_test(|repo| {
            let commits = repositories::commits::list(&repo)?;
            let initial_len = commits.len();
            let result = repositories::commit(&repo, "Should not work");
            assert!(result.is_err());
            let commits = repositories::commits::list(&repo)?;
            // We should not have added any commits
            assert_eq!(commits.len(), initial_len);
            Ok(())
        })
    }

    #[tokio::test]
    async fn test_command_commit_nothing_staged_but_file_modified() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            let commits = repositories::commits::list(&repo)?;
            let initial_len = commits.len();

            let labels_path = repo.path.join("labels.txt");
            util::fs::write_to_path(labels_path, "changing this guy, but not committing")?;

            let result = repositories::commit(&repo, "Should not work");
            assert!(result.is_err());
            let commits = repositories::commits::list(&repo)?;
            // We should not have added any commits
            assert_eq!(commits.len(), initial_len);
            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_status_has_txt_file() -> Result<(), OxenError> {
        test::run_empty_local_repo_test_async(|repo| async move {
            // Write to file
            let hello_file = repo.path.join("hello.txt");
            util::fs::write_to_path(hello_file, "Hello World")?;

            // Get status
            let repo_status = repositories::status(&repo).await?;
            assert_eq!(repo_status.staged_dirs.len(), 0);
            assert_eq!(repo_status.staged_files.len(), 0);
            assert_eq!(repo_status.untracked_files.len(), 1);
            assert_eq!(repo_status.untracked_dirs.len(), 0);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_merge_conflict_shows_in_status() -> Result<(), OxenError> {
        test::run_select_data_repo_test_no_commits_async("labels", |repo| async move {
            let labels_path = repo.path.join("labels.txt");
            repositories::add(&repo, &labels_path).await?;
            repositories::commit(&repo, "adding initial labels file")?;

            let og_branch = repositories::branches::current_branch(&repo)?.unwrap();

            // Add a "none" category on a branch
            let branch_name = "change-labels";
            repositories::branches::create_checkout(&repo, branch_name)?;

            test::modify_txt_file(&labels_path, "cat\ndog\nnone")?;
            repositories::add(&repo, &labels_path).await?;
            repositories::commit(&repo, "adding none category")?;

            // Add a "person" category on a the main branch
            repositories::checkout(&repo, og_branch.name).await?;

            test::modify_txt_file(&labels_path, "cat\ndog\nperson")?;
            repositories::add(&repo, &labels_path).await?;
            repositories::commit(&repo, "adding person category")?;

            // Try to merge in the changes
            let commit = repositories::merge::merge(&repo, branch_name).await?;

            // Make sure we didn't get a commit out of it
            assert!(commit.is_none());

            // Make sure we can access the conflicts in the status command
            let status = repositories::status(&repo).await?;
            assert_eq!(status.merge_conflicts.len(), 1);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_rm_regular_file() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Move the file to a new name
            let og_basename = PathBuf::from("README.md");
            let og_file = repo.path.join(&og_basename);
            util::fs::remove_file(og_file)?;

            let status = repositories::status(&repo).await?;
            status.print();

            assert_eq!(status.removed_files.len(), 1);

            let opts = RmOpts::from_path(&og_basename);
            repositories::rm(&repo, &opts).await?;
            let status = repositories::status(&repo).await?;
            status.print();

            assert_eq!(status.staged_files.len(), 1);
            assert_eq!(
                status.staged_files[&og_basename].status,
                StagedEntryStatus::Removed
            );

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_rm_directory_file() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Move the file to a new name
            let og_basename = PathBuf::from("README.md");
            let og_file = repo.path.join(&og_basename);
            util::fs::remove_file(og_file)?;

            let status = repositories::status(&repo).await?;
            status.print();

            assert_eq!(status.removed_files.len(), 1);

            let opts = RmOpts::from_path(&og_basename);
            repositories::rm(&repo, &opts).await?;
            let status = repositories::status(&repo).await?;
            status.print();

            assert_eq!(status.staged_files.len(), 1);
            assert_eq!(
                status.staged_files[&og_basename].status,
                StagedEntryStatus::Removed
            );

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_move_regular_file() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Move `README.md` to `README2.md`
            let og_basename = PathBuf::from("README.md");
            let og_file = repo.path.join(&og_basename);
            let new_basename = PathBuf::from("README2.md");
            let new_file = repo.path.join(new_basename);

            util::fs::rename(&og_file, &new_file)?;

            // Status before
            let status = repositories::status(&repo).await?;

            assert_eq!(status.moved_files.len(), 0);
            assert_eq!(status.removed_files.len(), 1);
            assert_eq!(status.untracked_files.len(), 1);

            // Add one file...
            repositories::add(&repo, &og_file).await?;
            let status = repositories::status(&repo).await?;
            // No notion of movement until the pair are added
            assert_eq!(status.moved_files.len(), 0);
            assert_eq!(status.staged_files.len(), 1);

            // Complete the pair
            repositories::add(&repo, &new_file).await?;
            let status = repositories::status(&repo).await?;
            assert_eq!(status.moved_files.len(), 1);
            assert_eq!(status.staged_files.len(), 2); // Staged files still operates on the addition + removal

            // Restore one file and break the pair
            repositories::restore(&repo, RestoreOpts::from_staged_path(og_basename)).await?;

            // Pair is broken; no more "moved"
            let status = repositories::status(&repo).await?;
            assert_eq!(status.moved_files.len(), 0);
            assert_eq!(status.staged_files.len(), 1);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_move_dir() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Move train/ to to new_train/train2
            let og_basename = PathBuf::from("train");
            let og_dir = repo.path.join(og_basename);
            let new_basename = PathBuf::from("new_train").join("train2");
            let new_dir = repo.path.join(new_basename);

            // Create the dir before move
            util::fs::create_dir_all(&new_dir)?;
            util::fs::rename(&og_dir, &new_dir)?;

            let status = repositories::status(&repo).await?;
            status.print();
            assert_eq!(status.moved_files.len(), 0);
            // TODO: v0_10_0 logic should have root and new_train/train2
            assert_eq!(status.untracked_dirs.len(), 1);
            // TODO: v0_10_0 test had 5 removed files here, but when the entire
            // directory was moved it doesn't make sense to show individual files
            assert_eq!(status.removed_files.len(), 1);

            // Add the removals
            repositories::add(&repo, &og_dir).await?;
            // repositories::add(&repo, &new_dir)?;

            let status = repositories::status(&repo).await?;
            // No moved files, 7 staged (the removals)
            assert_eq!(status.moved_files.len(), 0);
            assert_eq!(status.staged_files.len(), 7);
            assert_eq!(status.staged_dirs.len(), 1);

            // Complete the pairs
            repositories::add(&repo, &new_dir).await?;
            let status = repositories::status(&repo).await?;
            assert_eq!(status.moved_files.len(), 7);
            assert_eq!(status.staged_files.len(), 14);
            assert_eq!(status.staged_dirs.len(), 2);
            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_list_added_directories() -> Result<(), OxenError> {
        test::run_empty_local_repo_test_async(|repo| async move {
            // Write two files to a sub directory
            let repo_path = &repo.path;
            let training_data_dir = PathBuf::from("training_data");
            let sub_dir = repo_path.join(&training_data_dir);
            util::fs::create_dir_all(&sub_dir)?;

            let _ = test::add_txt_file_to_dir(&sub_dir, "Hello 1")?;
            let _ = test::add_txt_file_to_dir(&sub_dir, "Hello 2")?;

            repositories::add(&repo, &sub_dir).await?;

            // List files
            let status = repositories::status(&repo).await?;
            println!("status: {status:?}");
            status.print();
            let dirs = status.staged_dirs;

            // TODO: v0_10_0 logic should have root and training_data
            // We should just have training_data staged
            assert_eq!(dirs.len(), 1);
            let added_dir = dirs.get(&training_data_dir).unwrap();
            assert_eq!(added_dir.path, training_data_dir);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_remove_file_top_level() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            // Get head commit
            // List all entries in that commit
            let repo_path = &repo.path;
            let file_to_rm = repo_path.join("labels.txt");

            let status = repositories::status(&repo).await?;
            status.print();

            // Remove a committed file
            util::fs::remove_file(&file_to_rm)?;

            // List removed
            let status = repositories::status(&repo).await?;
            status.print();
            let files = status.removed_files;

            // There is one removed file, and nothing else
            assert_eq!(files.len(), 1);
            assert_eq!(status.staged_dirs.len(), 0);
            assert_eq!(status.staged_files.len(), 0);
            assert_eq!(status.untracked_dirs.len(), 0);
            assert_eq!(status.untracked_files.len(), 0);
            assert_eq!(status.modified_files.len(), 0);

            // And it is
            let relative_path = util::fs::path_relative_to_dir(&file_to_rm, repo_path)?;
            assert!(files.contains(&relative_path));

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_remove_file_in_subdirectory() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            let repo_path = &repo.path;
            let one_shot_file = repo_path
                .join("annotations")
                .join("train")
                .join("one_shot.csv");

            // Remove a committed file
            util::fs::remove_file(&one_shot_file)?;

            // List removed
            let status = repositories::status(&repo).await?;
            status.print();
            let files = status.removed_files;

            // There is one removed file
            assert_eq!(files.len(), 1);

            // And it is
            let relative_path = util::fs::path_relative_to_dir(&one_shot_file, repo_path)?;
            assert!(files.contains(&relative_path));

            Ok(())
        })
        .await
    }

    // Regression test: passing a deleted, tracked single-file path in opts.paths
    // should classify it as removed. The dir-based tree-side check in walk_status
    // only fires for directories in dir_hashes, so a missing file path was being
    // silently dropped.
    #[tokio::test]
    async fn test_status_remove_file_with_explicit_file_path() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            let repo_path = &repo.path;
            let target_file = repo_path
                .join("annotations")
                .join("train")
                .join("one_shot.csv");

            util::fs::remove_file(&target_file)?;

            let opts = StagedDataOpts::from_paths(std::slice::from_ref(&target_file));
            let status = repositories::status::status_from_opts(&repo, &opts).await?;
            status.print();

            let relative_path = util::fs::path_relative_to_dir(&target_file, repo_path)?;
            assert_eq!(status.removed_files.len(), 1);
            assert!(status.removed_files.contains(&relative_path));

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_modify_file_in_subdirectory() -> Result<(), OxenError> {
        test::run_training_data_repo_test_fully_committed_async(|repo| async move {
            let repo_path = &repo.path;
            let one_shot_file = repo_path
                .join("annotations")
                .join("train")
                .join("one_shot.csv");

            // Modify the committed file
            let one_shot_file = test::modify_txt_file(one_shot_file, "new content coming in hot")?;

            // List modified
            let status = repositories::status(&repo).await?;
            status.print();
            let files = status.modified_files;

            // There is one modified file
            assert_eq!(files.len(), 1);

            // And it is
            let relative_path = util::fs::path_relative_to_dir(one_shot_file, repo_path)?;
            assert!(files.contains(&relative_path));

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_list_untracked_directories_after_add() -> Result<(), OxenError> {
        test::run_empty_local_repo_test_async(|repo| async move {
            // Create 2 sub directories, one with  Write two files to a sub directory
            let repo_path = &repo.path;
            let train_dir = repo_path.join("train");
            util::fs::create_dir_all(&train_dir)?;
            let _ = test::add_img_file_to_dir(
                &train_dir,
                test::REPO_ROOT.join("data/test/images/cat_1.jpg").as_path(),
            )?;
            let _ = test::add_img_file_to_dir(
                &train_dir,
                test::REPO_ROOT.join("data/test/images/dog_1.jpg").as_path(),
            )?;
            let _ = test::add_img_file_to_dir(
                &train_dir,
                test::REPO_ROOT.join("data/test/images/cat_2.jpg").as_path(),
            )?;
            let _ = test::add_img_file_to_dir(
                &train_dir,
                test::REPO_ROOT.join("data/test/images/dog_2.jpg").as_path(),
            )?;

            let test_dir = repo_path.join("test");
            util::fs::create_dir_all(&test_dir)?;
            let _ = test::add_img_file_to_dir(
                &test_dir,
                test::REPO_ROOT.join("data/test/images/cat_3.jpg").as_path(),
            )?;
            let _ = test::add_img_file_to_dir(
                &test_dir,
                test::REPO_ROOT.join("data/test/images/dog_3.jpg").as_path(),
            )?;

            let valid_dir = repo_path.join("valid");
            util::fs::create_dir_all(&valid_dir)?;
            let _ = test::add_img_file_to_dir(
                &valid_dir,
                test::REPO_ROOT.join("data/test/images/dog_4.jpg").as_path(),
            )?;

            let base_file_1 = test::add_txt_file_to_dir(repo_path, "Hello 1")?;
            let _base_file_2 = test::add_txt_file_to_dir(repo_path, "Hello 2")?;
            let _base_file_3 = test::add_txt_file_to_dir(repo_path, "Hello 3")?;

            // At first there should be 3 untracked
            let status = repositories::status(&repo).await?;
            status.print();
            let untracked_dirs = status.untracked_dirs;
            assert_eq!(untracked_dirs.len(), 3);

            // Add the directory
            repositories::add(&repo, &train_dir).await?;
            // Add one file
            repositories::add(&repo, &base_file_1).await?;

            // List the files
            let status = repositories::status(&repo).await?;
            println!("status: {status:?}");
            status.print();
            let staged_files = status.staged_files;
            let staged_dirs = status.staged_dirs;
            let untracked_files = status.untracked_files;
            let untracked_dirs = status.untracked_dirs;

            // There is 5 added file and 2 added dirs (root + train)
            assert_eq!(staged_files.len(), 5);
            assert_eq!(staged_dirs.len(), 2);

            // There are 2 untracked files
            assert_eq!(untracked_files.len(), 2);
            // There are 2 untracked dirs at the top level
            assert_eq!(untracked_dirs.len(), 2);

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_status_list_modified_files() -> Result<(), OxenError> {
        test::run_empty_local_repo_test_async(|repo| async move {
            // Create entry_reader with no commits
            let repo_path = &repo.path;
            let hello_file = test::add_txt_file_to_dir(repo_path, "Hello 1")?;

            // add the file
            repositories::add(&repo, &hello_file).await?;

            // commit the file
            repositories::commit(&repo, "added hello 1")?;

            let status = repositories::status(&repo).await?;
            let mod_files = status.modified_files;
            assert_eq!(mod_files.len(), 0);

            // modify the file
            let hello_file = test::modify_txt_file(hello_file, "Hello 2")?;

            // List files
            let status = repositories::status(&repo).await?;
            status.print();
            let mod_files = status.modified_files;
            assert_eq!(mod_files.len(), 1);
            let relative_path = util::fs::path_relative_to_dir(hello_file, repo_path)?;
            assert!(mod_files.contains(&relative_path));

            Ok(())
        })
        .await
    }

    #[tokio::test]
    async fn test_command_status_modified_file_in_subdirectory() -> Result<(), OxenError> {
        test::run_select_data_repo_test_no_commits_async("annotations", |repo| async move {
            // Track & commit all the data
            let one_shot_path = repo.path.join("annotations/train/one_shot.csv");
            repositories::add(&repo, &repo.path).await?;
            repositories::commit(&repo, "Adding one shot")?;

            let branch_name = "feature/modify-data";
            repositories::branches::create_checkout(&repo, branch_name)?;

            let file_contents = "file,label\ntrain/cat_1.jpg,0\n";
            test::modify_txt_file(one_shot_path, file_contents)?;
            let status = repositories::status(&repo).await?;
            status.print();
            assert_eq!(status.modified_files.len(), 1);
            assert!(
                status
                    .modified_files
                    .contains(&PathBuf::from("annotations/train/one_shot.csv"))
            );

            Ok(())
        })
        .await
    }
}