1+ use gitbutler_command_context:: CommandContext ;
12use gitbutler_stack:: Stack ;
23
34/// Makes a Branch struct with a bunch of default values.
45///
56/// This assumes that the only relevant properties for your test are the head
67/// and tree Oids.
7- fn make_branch ( head : git2:: Oid , tree : git2:: Oid ) -> Stack {
8+ fn make_branch ( ctx : & CommandContext , head : git2:: Oid , tree : git2:: Oid ) -> Stack {
89 #[ allow( deprecated) ] // this is a test
910 let mut branch = Stack :: new (
1011 "branchy branch" . into ( ) ,
@@ -20,6 +21,7 @@ fn make_branch(head: git2::Oid, tree: git2::Oid) -> Stack {
2021 branch. created_timestamp_ms = 69420 ;
2122 branch. updated_timestamp_ms = 69420 ;
2223 branch. notes = "bla bla bla" . into ( ) ;
24+ branch. initialize ( ctx, false ) . unwrap ( ) ;
2325 branch
2426}
2527
@@ -29,21 +31,29 @@ mod compute_updated_branch_head {
2931 use gitbutler_cherry_pick:: RepositoryExt as _;
3032 use gitbutler_commit:: commit_ext:: CommitExt ;
3133 use gitbutler_oxidize:: RepoExt ;
32- use gitbutler_testsupport:: testing_repository:: {
33- assert_commit_tree_matches, assert_tree_matches, TestingRepository ,
34+ use gitbutler_testsupport:: {
35+ testing_repository:: { assert_commit_tree_matches, assert_tree_matches, TestingRepository } ,
36+ virtual_branches:: set_test_target,
3437 } ;
3538 use gitbutler_workspace:: { compute_updated_branch_head, BranchHeadAndTree } ;
3639
3740 /// When the head ID is the same as the branch ID, we should return the same Oids.
3841 #[ test]
3942 fn head_id_is_the_same ( ) {
4043 let test_repository = TestingRepository :: open ( ) ;
44+ let data_dir = gitbutler_testsupport:: paths:: data_dir ( ) ;
45+ let projects = gitbutler_project:: Controller :: from_path ( data_dir. path ( ) ) ;
46+ let project = projects
47+ . add ( test_repository. repository . path ( ) )
48+ . expect ( "failed to add project" ) ;
49+ let ctx = CommandContext :: open ( & project, but_settings:: AppSettings :: default ( ) ) . unwrap ( ) ;
50+ set_test_target ( & ctx) . unwrap ( ) ;
4151
4252 let base_commit = test_repository. commit_tree ( None , & [ ( "foo.txt" , "foo" ) ] ) ;
4353 let head = test_repository. commit_tree ( Some ( & base_commit) , & [ ( "foo.txt" , "bar" ) ] ) ;
4454 let tree = test_repository. commit_tree ( Some ( & head) , & [ ( "foo.txt" , "baz" ) ] ) ;
4555
46- let stack = make_branch ( head. id ( ) , tree. tree_id ( ) ) ;
56+ let stack = make_branch ( & ctx , head. id ( ) , tree. tree_id ( ) ) ;
4757
4858 let BranchHeadAndTree { head, tree } =
4959 compute_updated_branch_head ( & test_repository. repository , & stack, head. id ( ) ) . unwrap ( ) ;
@@ -63,13 +73,20 @@ mod compute_updated_branch_head {
6373 #[ test]
6474 fn head_id_is_different ( ) {
6575 let test_repository = TestingRepository :: open ( ) ;
76+ let data_dir = gitbutler_testsupport:: paths:: data_dir ( ) ;
77+ let projects = gitbutler_project:: Controller :: from_path ( data_dir. path ( ) ) ;
78+ let project = projects
79+ . add ( test_repository. repository . path ( ) )
80+ . expect ( "failed to add project" ) ;
81+ let ctx = CommandContext :: open ( & project, but_settings:: AppSettings :: default ( ) ) . unwrap ( ) ;
82+ set_test_target ( & ctx) . unwrap ( ) ;
6683
6784 let base_commit = test_repository. commit_tree ( None , & [ ( "foo.txt" , "foo" ) ] ) ;
6885 let head = test_repository. commit_tree ( Some ( & base_commit) , & [ ( "foo.txt" , "bar" ) ] ) ;
6986 let tree =
7087 test_repository. commit_tree ( Some ( & head) , & [ ( "foo.txt" , "bar" ) , ( "bar.txt" , "baz" ) ] ) ;
7188
72- let stack = make_branch ( head. id ( ) , tree. tree_id ( ) ) ;
89+ let stack = make_branch ( & ctx , head. id ( ) , tree. tree_id ( ) ) ;
7390
7491 let new_head = test_repository. commit_tree ( Some ( & base_commit) , & [ ( "foo.txt" , "new" ) ] ) ;
7592
@@ -94,12 +111,19 @@ mod compute_updated_branch_head {
94111 #[ test]
95112 fn tree_conflicts ( ) {
96113 let test_repository = TestingRepository :: open ( ) ;
114+ let data_dir = gitbutler_testsupport:: paths:: data_dir ( ) ;
115+ let projects = gitbutler_project:: Controller :: from_path ( data_dir. path ( ) ) ;
116+ let project = projects
117+ . add ( test_repository. repository . path ( ) )
118+ . expect ( "failed to add project" ) ;
119+ let ctx = CommandContext :: open ( & project, but_settings:: AppSettings :: default ( ) ) . unwrap ( ) ;
120+ set_test_target ( & ctx) . unwrap ( ) ;
97121
98122 let base_commit = test_repository. commit_tree ( None , & [ ( "foo.txt" , "foo" ) ] ) ;
99123 let head = test_repository. commit_tree ( Some ( & base_commit) , & [ ( "foo.txt" , "bar" ) ] ) ;
100124 let tree = test_repository. commit_tree ( Some ( & head) , & [ ( "foo.txt" , "baz" ) ] ) ;
101125
102- let stack = make_branch ( head. id ( ) , tree. tree_id ( ) ) ;
126+ let stack = make_branch ( & ctx , head. id ( ) , tree. tree_id ( ) ) ;
103127
104128 let new_head = test_repository. commit_tree ( Some ( & base_commit) , & [ ( "foo.txt" , "new" ) ] ) ;
105129
0 commit comments