@@ -137,12 +137,25 @@ impl RepositoryConfig {
137
137
}
138
138
139
139
pub struct Repository {
140
+ /// bla
140
141
pub checkout_path : TempDir ,
141
142
repository : git2:: Repository ,
142
143
pub credentials : Credentials ,
143
144
}
144
145
145
146
impl Repository {
147
+ /// Clones the crate index from a remote git server and returns a
148
+ /// `Repository` struct to interact with the local copy of the crate index.
149
+ ///
150
+ /// Note that the `user` configuration for the repository is automatically
151
+ /// set to `bors <[email protected] >`.
152
+ ///
153
+ /// # Errors
154
+ ///
155
+ /// - If creation of a temporary folder for cloning the crate index fails.
156
+ /// - If cloning the crate index fails.
157
+ /// - If reading the global git config fails.
158
+ ///
146
159
pub fn open ( repository_config : & RepositoryConfig ) -> Result < Self , PerformError > {
147
160
let checkout_path = tempfile:: Builder :: new ( ) . prefix ( "git" ) . tempdir ( ) ?;
148
161
@@ -174,12 +187,21 @@ impl Repository {
174
187
} )
175
188
}
176
189
190
+ /// Returns the absolute path to the crate index file that corresponds to
191
+ /// the given crate name.
192
+ ///
193
+ /// This is similar to [Self::relative_index_file], but returns the absolute
194
+ /// path.
177
195
pub fn index_file ( & self , name : & str ) -> PathBuf {
178
196
self . checkout_path
179
197
. path ( )
180
198
. join ( Self :: relative_index_file ( name) )
181
199
}
182
200
201
+ /// Returns the relative path to the crate index file that corresponds to
202
+ /// the given crate name.
203
+ ///
204
+ /// see <https://doc.rust-lang.org/cargo/reference/registries.html#index-format>
183
205
pub fn relative_index_file ( name : & str ) -> PathBuf {
184
206
let name = name. to_lowercase ( ) ;
185
207
match name. len ( ) {
@@ -190,10 +212,22 @@ impl Repository {
190
212
}
191
213
}
192
214
215
+ /// Returns the [Object ID](git2::Oid) of the currently checked out commit
216
+ /// in the local crate index repository.
217
+ ///
218
+ /// # Errors
219
+ ///
220
+ /// - If the `HEAD` pointer can't be retrieved.
221
+ ///
193
222
pub fn head_oid ( & self ) -> Result < git2:: Oid , PerformError > {
194
223
Ok ( self . repository . head ( ) ?. target ( ) . unwrap ( ) )
195
224
}
196
225
226
+ /// Commits the specified file with the specified commit message and pushes
227
+ /// the commit to the `master` branch on the `origin` remote.
228
+ ///
229
+ /// Note that `modified_file` expects a file path **relative** to the
230
+ /// repository working folder!
197
231
fn perform_commit_and_push ( & self , msg : & str , modified_file : & Path ) -> Result < ( ) , PerformError > {
198
232
// git add $file
199
233
let mut index = self . repository . index ( ) ?;
@@ -241,6 +275,13 @@ impl Repository {
241
275
ref_status
242
276
}
243
277
278
+ /// Commits the specified file with the specified commit message and pushes
279
+ /// the commit to the `master` branch on the `origin` remote.
280
+ ///
281
+ /// Note that `modified_file` expects an **absolute** file path!
282
+ ///
283
+ /// This function also prints the commit message and a success or failure
284
+ /// message to the console.
244
285
pub fn commit_and_push ( & self , message : & str , modified_file : & Path ) -> Result < ( ) , PerformError > {
245
286
println ! ( "Committing and pushing \" {}\" " , message) ;
246
287
@@ -253,6 +294,8 @@ impl Repository {
253
294
} )
254
295
}
255
296
297
+ /// Fetches any changes from the `origin` remote and performs a hard reset
298
+ /// to the tip of the `origin/master` branch.
256
299
pub fn reset_head ( & self ) -> Result < ( ) , PerformError > {
257
300
let mut origin = self . repository . find_remote ( "origin" ) ?;
258
301
let original_head = self . head_oid ( ) ?;
0 commit comments