@@ -11,57 +11,63 @@ pub struct GitRepoFixture {
1111}
1212
1313impl GitRepoFixture {
14- /// Create a repository with a clean tag (Tier 1: major.minor.patch)
15- pub fn tagged ( tag : & str ) -> Result < Self , Box < dyn std:: error:: Error > > {
14+ /// Create an empty repository without any tags
15+ pub fn empty ( ) -> Result < Self , Box < dyn std:: error:: Error > > {
1616 let test_dir = TestDir :: new ( ) ?;
1717 let git_impl = get_git_impl ( ) ;
1818
19- // Perform atomic Git operations in sequence with error context
19+ // Perform atomic Git operations with error context
2020 git_impl
2121 . init_repo ( & test_dir)
2222 . map_err ( |e| format ! ( "Failed to initialize Git repo: {e}" ) ) ?;
2323
24- // Verify repository was created properly before tagging
24+ // Verify repository was created properly
2525 if !test_dir. path ( ) . join ( ".git" ) . exists ( ) {
2626 return Err ( "Git repository was not properly initialized" . into ( ) ) ;
2727 }
2828
29- git_impl
30- . create_tag ( & test_dir, tag)
29+ Ok ( Self { test_dir, git_impl } )
30+ }
31+
32+ /// Create a repository with a clean tag (Tier 1: major.minor.patch)
33+ pub fn tagged ( tag : & str ) -> Result < Self , Box < dyn std:: error:: Error > > {
34+ let fixture = Self :: empty ( ) ?;
35+
36+ fixture
37+ . git_impl
38+ . create_tag ( & fixture. test_dir , tag)
3139 . map_err ( |e| format ! ( "Failed to create tag '{tag}': {e}" ) ) ?;
3240
33- Ok ( Self { test_dir , git_impl } )
41+ Ok ( fixture )
3442 }
3543
3644 /// Create a repository with distance from tag (Tier 2: major.minor.patch.post<distance>+branch.<commit>)
3745 pub fn with_distance ( tag : & str , commits : u32 ) -> Result < Self , Box < dyn std:: error:: Error > > {
38- let test_dir = TestDir :: new ( ) ?;
39- let git_impl = get_git_impl ( ) ;
40-
41- git_impl. init_repo ( & test_dir) ?;
42- git_impl. create_tag ( & test_dir, tag) ?;
46+ let fixture = Self :: tagged ( tag) ?;
4347
4448 // Create additional commits for distance
4549 for i in 0 ..commits {
46- test_dir. create_file ( format ! ( "file{}.txt" , i + 1 ) , "content" ) ?;
47- git_impl. create_commit ( & test_dir, & format ! ( "Commit {}" , i + 1 ) ) ?;
50+ fixture
51+ . test_dir
52+ . create_file ( format ! ( "file{}.txt" , i + 1 ) , "content" ) ?;
53+ fixture
54+ . git_impl
55+ . create_commit ( & fixture. test_dir , & format ! ( "Commit {}" , i + 1 ) ) ?;
4856 }
4957
50- Ok ( Self { test_dir , git_impl } )
58+ Ok ( fixture )
5159 }
5260
5361 /// Create a repository with dirty working directory (Tier 3: major.minor.patch.dev<timestamp>+branch.<commit>)
5462 pub fn dirty ( tag : & str ) -> Result < Self , Box < dyn std:: error:: Error > > {
55- let test_dir = TestDir :: new ( ) ?;
56- let git_impl = get_git_impl ( ) ;
57-
58- git_impl. init_repo ( & test_dir) ?;
59- git_impl. create_tag ( & test_dir, tag) ?;
63+ let fixture = Self :: tagged ( tag) ?;
6064
6165 // Create uncommitted changes to make it dirty
62- test_dir. create_file ( "dirty.txt" , "uncommitted changes" ) ?;
66+ fixture
67+ . test_dir
68+ . create_file ( "dirty.txt" , "uncommitted changes" ) ?;
6369
64- Ok ( Self { test_dir , git_impl } )
70+ Ok ( fixture )
6571 }
6672
6773 /// Get the path to the test directory
0 commit comments