1- use anyhow:: anyhow;
1+ use anyhow:: { anyhow, Context } ;
22use std:: collections:: HashMap ;
33use std:: path:: { Path , PathBuf } ;
44
@@ -144,7 +144,10 @@ pub struct Repository {
144144
145145impl Repository {
146146 pub fn open ( repository_config : & RepositoryConfig ) -> anyhow:: Result < Self > {
147- let checkout_path = tempfile:: Builder :: new ( ) . prefix ( "git" ) . tempdir ( ) ?;
147+ let checkout_path = tempfile:: Builder :: new ( )
148+ . prefix ( "git" )
149+ . tempdir ( )
150+ . context ( "Failed to create temporary directory" ) ?;
148151
149152 let repository = git2:: build:: RepoBuilder :: new ( )
150153 . fetch_options ( Self :: fetch_options ( & repository_config. credentials ) )
@@ -159,13 +162,21 @@ impl Repository {
159162 . clone (
160163 repository_config. index_location . as_str ( ) ,
161164 checkout_path. path ( ) ,
162- ) ?;
165+ )
166+ . context ( "Failed to clone index repository" ) ?;
163167
164168 // All commits to the index registry made through crates.io will be made by bors, the Rust
165169 // community's friendly GitHub bot.
166- let mut cfg = repository. config ( ) ?;
167- cfg. set_str ( "user.name" , "bors" ) ?;
168- cfg
. set_str ( "user.email" , "[email protected] " ) ?
; 170+
171+ let mut cfg = repository
172+ . config ( )
173+ . context ( "Failed to read git configuration" ) ?;
174+
175+ cfg. set_str ( "user.name" , "bors" )
176+ . context ( "Failed to set user name" ) ?;
177+
178+ cfg
. set_str ( "user.email" , "[email protected] " ) 179+ . context ( "Failed to set user email address" ) ?;
169180
170181 Ok ( Self {
171182 checkout_path,
@@ -191,7 +202,9 @@ impl Repository {
191202 }
192203
193204 pub fn head_oid ( & self ) -> anyhow:: Result < git2:: Oid > {
194- Ok ( self . repository . head ( ) ?. target ( ) . unwrap ( ) )
205+ let repo = & self . repository ;
206+ let head = repo. head ( ) . context ( "Failed to read HEAD reference" ) ?;
207+ Ok ( head. target ( ) . unwrap ( ) )
195208 }
196209
197210 fn perform_commit_and_push ( & self , msg : & str , modified_file : & Path ) -> anyhow:: Result < ( ) > {
0 commit comments