Commit c664c66 1 parent 94095f1 commit c664c66 Copy full SHA for c664c66
File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -310,6 +310,26 @@ impl Repository for Github {
310
310
}
311
311
}
312
312
313
+ async fn switch_branch ( & self , branch_name : & str ) -> Result < ( ) , CoffeeError > {
314
+ let repo = git2:: Repository :: open ( & self . url . path_string )
315
+ . map_err ( |err| error ! ( "{}" , err. message( ) ) ) ?;
316
+ let mut remote = repo
317
+ . find_remote ( "origin" )
318
+ . map_err ( |err| error ! ( "{}" , err. message( ) ) ) ?;
319
+ remote
320
+ . fetch ( & [ & branch_name] , None , None )
321
+ . map_err ( |err| error ! ( "{}" , err. message( ) ) ) ?;
322
+ let oid = repo
323
+ . refname_to_id ( & format ! ( "refs/remotes/origin/{}" , branch_name) )
324
+ . map_err ( |err| error ! ( "{}" , err. message( ) ) ) ?;
325
+ let obj = repo
326
+ . find_object ( oid, None )
327
+ . map_err ( |err| error ! ( "{}" , err. message( ) ) ) ?;
328
+ repo. reset ( & obj, git2:: ResetType :: Hard , None )
329
+ . map_err ( |err| error ! ( "{}" , err. message( ) ) ) ?;
330
+ Ok ( ( ) )
331
+ }
332
+
313
333
/// list of the plugin installed inside the repository.
314
334
async fn list ( & self ) -> Result < Vec < Plugin > , CoffeeError > {
315
335
Ok ( self . plugins . clone ( ) )
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ pub trait Repository: Any {
30
30
/// recover the repository from the commit id.
31
31
async fn recover ( & mut self ) -> Result < ( ) , CoffeeError > ;
32
32
33
+ /// switch to the specified branch.
34
+ async fn switch_branch ( & self , branch_name : & str ) -> Result < ( ) , CoffeeError > ;
35
+
33
36
/// return the name of the repository.
34
37
fn name ( & self ) -> String ;
35
38
You can’t perform that action at this time.
0 commit comments