@@ -82,21 +82,23 @@ def get_branches(self, repo_dir: str):
82
82
83
83
return set (branches )
84
84
85
- def create_branch_and_push_all_changes (self , repo_dir : str , branch_name : str , commit_message : str ):
86
- repo = git .repo .Repo (repo_dir )
85
+ def create_branch_and_push_all_changes (self , branch_name : str , commit_message : str ):
86
+ base_branch = self .__repo .get_branch (self .__repo .default_branch )
87
+ base_tree = self .__repo .get_git_tree (base_branch .commit .sha )
87
88
88
- new_branch = repo . create_head ( branch_name )
89
+ self . __repo . create_git_ref ( ref = f"refs/heads/ { branch_name } " , sha = base_branch . commit . sha )
89
90
90
- repo .git .checkout (new_branch )
91
- repo .git .add ("-A" )
91
+ new_tree = self .__repo .create_git_tree ([], base_tree .sha )
92
+ commit = self .__repo .create_git_commit (
93
+ message = commit_message ,
94
+ tree = new_tree .sha ,
95
+ parents = [base_branch .commit .sha ]
96
+ )
92
97
93
- if self .__config .gpg_key_id :
94
- repo .git .commit ('-S' , f'--gpg-sign={ self .__config .gpg_key_id } ' , '-m' , commit_message )
95
- else :
96
- repo .index .commit (commit_message )
98
+ self .__repo .update_git_ref (ref = f"heads/{ branch_name } " , sha = commit .sha )
97
99
98
100
if not self .__config .dry_run :
99
- repo . git . push ( "--set-upstream" , "origin" , branch_name )
101
+ logging . info ( f"Changes pushed to branch { branch_name } " )
100
102
101
103
def branch_exists (self , branch_name : str ):
102
104
remote_branch_name = f'origin/{ branch_name } '
0 commit comments