@@ -3,7 +3,7 @@ use code2prompt::git::{get_git_diff, get_git_diff_between_branches, get_git_log}
3
3
#[ cfg( test) ]
4
4
mod tests {
5
5
use super :: * ;
6
- use git2:: { Repository , Signature } ;
6
+ use git2:: { Repository , RepositoryInitOptions , Signature } ;
7
7
use std:: fs;
8
8
use tempfile:: TempDir ;
9
9
@@ -69,7 +69,10 @@ mod tests {
69
69
let repo_path = temp_dir. path ( ) ;
70
70
71
71
// Initialize a new Git repository
72
- let repo = Repository :: init ( repo_path) . expect ( "Failed to initialize repository" ) ;
72
+ let mut binding = RepositoryInitOptions :: new ( ) ;
73
+ let init_options = binding. initial_head ( "master" ) ;
74
+ let repo = Repository :: init_opts ( repo_path, init_options)
75
+ . expect ( "Failed to initialize repository" ) ;
73
76
74
77
// Create a new file in the repository
75
78
let file_path = repo_path. join ( "test_file.txt" ) ;
@@ -99,13 +102,21 @@ mod tests {
99
102
. expect ( "Failed to commit" ) ;
100
103
101
104
// Create a new branch and make a commit on the master branch
102
- repo. branch ( "development" , & repo. find_commit ( master_commit) . expect ( "Failed to find commit" ) , false )
103
- . expect ( "Failed to create new branch" ) ;
105
+ repo. branch (
106
+ "development" ,
107
+ & repo
108
+ . find_commit ( master_commit)
109
+ . expect ( "Failed to find commit" ) ,
110
+ false ,
111
+ )
112
+ . expect ( "Failed to create new branch" ) ;
104
113
105
114
// Modify the file in the new branch
106
- repo. set_head ( "refs/heads/development" ) . expect ( "Failed to set HEAD" ) ;
115
+ repo. set_head ( "refs/heads/development" )
116
+ . expect ( "Failed to set HEAD" ) ;
107
117
repo. checkout_head ( None ) . expect ( "Failed to checkout HEAD" ) ;
108
- fs:: write ( & file_path, "Content in new branch" ) . expect ( "Failed to modify test file in new branch" ) ;
118
+ fs:: write ( & file_path, "Content in new branch" )
119
+ . expect ( "Failed to modify test file in new branch" ) ;
109
120
110
121
let mut index = repo. index ( ) . expect ( "Failed to get repository index" ) ;
111
122
index
@@ -122,7 +133,9 @@ mod tests {
122
133
& signature,
123
134
"New commit in branch development" ,
124
135
& tree,
125
- & [ & repo. find_commit ( master_commit) . expect ( "Failed to find commit" ) ] ,
136
+ & [ & repo
137
+ . find_commit ( master_commit)
138
+ . expect ( "Failed to find commit" ) ] ,
126
139
)
127
140
. expect ( "Failed to commit in new branch" ) ;
128
141
@@ -145,7 +158,10 @@ mod tests {
145
158
let repo_path = temp_dir. path ( ) ;
146
159
147
160
// Initialize a new Git repository
148
- let repo = Repository :: init ( repo_path) . expect ( "Failed to initialize repository" ) ;
161
+ let mut binding = RepositoryInitOptions :: new ( ) ;
162
+ let init_options = binding. initial_head ( "master" ) ;
163
+ let repo = Repository :: init_opts ( repo_path, init_options)
164
+ . expect ( "Failed to initialize repository" ) ;
149
165
150
166
// Create a new file in the repository
151
167
let file_path = repo_path. join ( "test_file.txt" ) ;
@@ -175,13 +191,21 @@ mod tests {
175
191
. expect ( "Failed to commit" ) ;
176
192
177
193
// Create a new branch and make a commit on the master branch
178
- repo. branch ( "development" , & repo. find_commit ( master_commit) . expect ( "Failed to find commit" ) , false )
179
- . expect ( "Failed to create new branch" ) ;
194
+ repo. branch (
195
+ "development" ,
196
+ & repo
197
+ . find_commit ( master_commit)
198
+ . expect ( "Failed to find commit" ) ,
199
+ false ,
200
+ )
201
+ . expect ( "Failed to create new branch" ) ;
180
202
181
203
// Modify the file in the new branch
182
- repo. set_head ( "refs/heads/development" ) . expect ( "Failed to set HEAD" ) ;
204
+ repo. set_head ( "refs/heads/development" )
205
+ . expect ( "Failed to set HEAD" ) ;
183
206
repo. checkout_head ( None ) . expect ( "Failed to checkout HEAD" ) ;
184
- fs:: write ( & file_path, "Content in development" ) . expect ( "Failed to modify test file in new branch" ) ;
207
+ fs:: write ( & file_path, "Content in development" )
208
+ . expect ( "Failed to modify test file in new branch" ) ;
185
209
186
210
let mut index = repo. index ( ) . expect ( "Failed to get repository index" ) ;
187
211
index
@@ -198,12 +222,15 @@ mod tests {
198
222
& signature,
199
223
"First commit in development" ,
200
224
& tree,
201
- & [ & repo. find_commit ( master_commit) . expect ( "Failed to find commit" ) ] ,
225
+ & [ & repo
226
+ . find_commit ( master_commit)
227
+ . expect ( "Failed to find commit" ) ] ,
202
228
)
203
229
. expect ( "Failed to commit in new branch" ) ;
204
230
205
231
// Make a second commit in the development branch
206
- fs:: write ( & file_path, "Second content in development" ) . expect ( "Failed to modify test file in new branch" ) ;
232
+ fs:: write ( & file_path, "Second content in development" )
233
+ . expect ( "Failed to modify test file in new branch" ) ;
207
234
208
235
let mut index = repo. index ( ) . expect ( "Failed to get repository index" ) ;
209
236
index
@@ -220,7 +247,9 @@ mod tests {
220
247
& signature,
221
248
"Second commit in development" ,
222
249
& tree,
223
- & [ & repo. find_commit ( repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ) . expect ( "Failed to find commit" ) ] ,
250
+ & [ & repo
251
+ . find_commit ( repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) )
252
+ . expect ( "Failed to find commit" ) ] ,
224
253
)
225
254
. expect ( "Failed to commit second change in new branch" ) ;
226
255
0 commit comments