33#include "git2/rebase.h"
44#include "posix.h"
55#include "signature.h"
6+ #include "../submodule/submodule_helpers.h"
67
78#include <fcntl.h>
89
@@ -12,9 +13,44 @@ static git_signature *signature;
1213// Fixture setup and teardown
1314void test_rebase_submodule__initialize (void )
1415{
16+ git_index * index ;
17+ git_oid tree_oid , commit_id ;
18+ git_tree * tree ;
19+ git_commit * parent ;
20+ git_object * obj ;
21+ git_reference * master_ref ;
22+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT ;
23+ opts .checkout_strategy = GIT_CHECKOUT_FORCE ;
24+
1525 repo = cl_git_sandbox_init ("rebase-submodule" );
1626 cl_git_pass (git_signature_new (& signature ,
1727 "Rebaser" , "rebaser@rebaser.rb" , 1405694510 , 0 ));
28+
29+ rewrite_gitmodules (git_repository_workdir (repo ));
30+
31+ git_submodule_set_url (repo , "my-submodule" , git_repository_path (repo ));
32+
33+ /* We have to commit the rewritten .gitmodules file */
34+ git_repository_index (& index , repo );
35+ git_index_add_bypath (index , ".gitmodules" );
36+ git_index_write_tree (& tree_oid , index );
37+ git_index_free (index );
38+
39+ cl_git_pass (git_tree_lookup (& tree , repo , & tree_oid ));
40+
41+ git_repository_head (& master_ref , repo );
42+ cl_git_pass (git_commit_lookup (& parent , repo , git_reference_target (master_ref )));
43+
44+ cl_git_pass (git_commit_create_v (& commit_id , repo , git_reference_name (master_ref ), signature , signature , NULL , "Fixup .gitmodules" , tree , 1 , parent ));
45+
46+ /* And a final reset, for good measure */
47+ git_object_lookup (& obj , repo , & commit_id , GIT_OBJ_COMMIT );
48+ cl_git_pass (git_reset (repo , obj , GIT_RESET_HARD , & opts ));
49+
50+ git_object_free (obj );
51+ git_commit_free (parent );
52+ git_reference_free (master_ref );
53+ git_tree_free (tree );
1854}
1955
2056void test_rebase_submodule__cleanup (void )
@@ -31,20 +67,13 @@ void test_rebase_submodule__init_untracked(void)
3167 git_buf untracked_path = GIT_BUF_INIT ;
3268 FILE * fp ;
3369 git_submodule * submodule ;
34- git_config * config ;
3570
3671 cl_git_pass (git_reference_lookup (& branch_ref , repo , "refs/heads/asparagus" ));
3772 cl_git_pass (git_reference_lookup (& upstream_ref , repo , "refs/heads/master" ));
3873
3974 cl_git_pass (git_annotated_commit_from_ref (& branch_head , repo , branch_ref ));
4075 cl_git_pass (git_annotated_commit_from_ref (& upstream_head , repo , upstream_ref ));
4176
42- git_repository_config (& config , repo );
43-
44- cl_git_pass (git_config_set_string (config , "submodule.my-submodule.url" , git_repository_path (repo )));
45-
46- git_config_free (config );
47-
4877 cl_git_pass (git_submodule_lookup (& submodule , repo , "my-submodule" ));
4978 cl_git_pass (git_submodule_update (submodule , 1 , NULL ));
5079
0 commit comments