@@ -4,7 +4,6 @@ use std::io::Write;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use std:: process:: Command ;
6
6
7
- use swirl:: PerformError ;
8
7
use tempfile:: TempDir ;
9
8
use url:: Url ;
10
9
@@ -197,7 +196,7 @@ impl Repository {
197
196
/// - If cloning the crate index fails.
198
197
/// - If reading the global git config fails.
199
198
///
200
- pub fn open ( repository_config : & RepositoryConfig ) -> Result < Self , PerformError > {
199
+ pub fn open ( repository_config : & RepositoryConfig ) -> anyhow :: Result < Self > {
201
200
let checkout_path = tempfile:: Builder :: new ( ) . prefix ( "git" ) . tempdir ( ) ?;
202
201
203
202
let repository = git2:: build:: RepoBuilder :: new ( )
@@ -260,7 +259,7 @@ impl Repository {
260
259
///
261
260
/// - If the `HEAD` pointer can't be retrieved.
262
261
///
263
- pub fn head_oid ( & self ) -> Result < git2:: Oid , PerformError > {
262
+ pub fn head_oid ( & self ) -> anyhow :: Result < git2:: Oid > {
264
263
Ok ( self . repository . head ( ) ?. target ( ) . unwrap ( ) )
265
264
}
266
265
@@ -269,7 +268,7 @@ impl Repository {
269
268
///
270
269
/// Note that `modified_file` expects a file path **relative** to the
271
270
/// repository working folder!
272
- fn perform_commit_and_push ( & self , msg : & str , modified_file : & Path ) -> Result < ( ) , PerformError > {
271
+ fn perform_commit_and_push ( & self , msg : & str , modified_file : & Path ) -> anyhow :: Result < ( ) > {
273
272
// git add $file
274
273
let mut index = self . repository . index ( ) ?;
275
274
index. add_path ( modified_file) ?;
@@ -288,7 +287,7 @@ impl Repository {
288
287
}
289
288
290
289
/// Push the current branch to the provided refname
291
- fn push ( & self , refspec : & str ) -> Result < ( ) , PerformError > {
290
+ fn push ( & self , refspec : & str ) -> anyhow :: Result < ( ) > {
292
291
let mut ref_status = Ok ( ( ) ) ;
293
292
let mut callback_called = false ;
294
293
{
@@ -299,7 +298,7 @@ impl Repository {
299
298
} ) ;
300
299
callbacks. push_update_reference ( |_, status| {
301
300
if let Some ( s) = status {
302
- ref_status = Err ( format ! ( "failed to push a ref: {}" , s) . into ( ) )
301
+ ref_status = Err ( anyhow ! ( "failed to push a ref: {}" , s) )
303
302
}
304
303
callback_called = true ;
305
304
Ok ( ( ) )
@@ -310,7 +309,7 @@ impl Repository {
310
309
}
311
310
312
311
if !callback_called {
313
- ref_status = Err ( "update_reference callback was not called" . into ( ) ) ;
312
+ ref_status = Err ( anyhow ! ( "update_reference callback was not called" ) ) ;
314
313
}
315
314
316
315
ref_status
@@ -323,7 +322,7 @@ impl Repository {
323
322
///
324
323
/// This function also prints the commit message and a success or failure
325
324
/// message to the console.
326
- pub fn commit_and_push ( & self , message : & str , modified_file : & Path ) -> Result < ( ) , PerformError > {
325
+ pub fn commit_and_push ( & self , message : & str , modified_file : & Path ) -> anyhow :: Result < ( ) > {
327
326
println ! ( "Committing and pushing \" {}\" " , message) ;
328
327
329
328
let relative_path = modified_file. strip_prefix ( self . checkout_path . path ( ) ) ?;
@@ -337,7 +336,7 @@ impl Repository {
337
336
338
337
/// Fetches any changes from the `origin` remote and performs a hard reset
339
338
/// to the tip of the `origin/master` branch.
340
- pub fn reset_head ( & self ) -> Result < ( ) , PerformError > {
339
+ pub fn reset_head ( & self ) -> anyhow :: Result < ( ) > {
341
340
let mut origin = self . repository . find_remote ( "origin" ) ?;
342
341
let original_head = self . head_oid ( ) ?;
343
342
origin. fetch (
@@ -371,7 +370,7 @@ impl Repository {
371
370
}
372
371
373
372
/// Reset `HEAD` to a single commit with all the index contents, but no parent
374
- pub fn squash_to_single_commit ( & self , msg : & str ) -> Result < ( ) , PerformError > {
373
+ pub fn squash_to_single_commit ( & self , msg : & str ) -> anyhow :: Result < ( ) > {
375
374
let tree = self . repository . find_commit ( self . head_oid ( ) ?) ?. tree ( ) ?;
376
375
let sig = self . repository . signature ( ) ?;
377
376
@@ -393,7 +392,7 @@ impl Repository {
393
392
///
394
393
/// This function also temporarily sets the `GIT_SSH_COMMAND` environment
395
394
/// variable to ensure that `git push` commands are able to succeed.
396
- pub fn run_command ( & self , command : & mut Command ) -> Result < ( ) , PerformError > {
395
+ pub fn run_command ( & self , command : & mut Command ) -> anyhow :: Result < ( ) > {
397
396
let checkout_path = self . checkout_path . path ( ) ;
398
397
command. current_dir ( checkout_path) ;
399
398
@@ -409,8 +408,7 @@ impl Repository {
409
408
let output = command. output ( ) ?;
410
409
if !output. status . success ( ) {
411
410
let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
412
- let message = format ! ( "Running git command failed with: {}" , stderr) ;
413
- return Err ( message. into ( ) ) ;
411
+ return Err ( anyhow ! ( "Running git command failed with: {}" , stderr) ) ;
414
412
}
415
413
416
414
Ok ( ( ) )
0 commit comments