@@ -160,8 +160,8 @@ impl<'cfg> PathSource<'cfg> {
160
160
161
161
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).
162
162
if no_include_option {
163
- if let Some ( result) = self . discover_git_and_list_files ( pkg, root, & mut filter) {
164
- return result;
163
+ if let Some ( result) = self . discover_git_and_list_files ( pkg, root, & mut filter) ? {
164
+ return Ok ( result) ;
165
165
}
166
166
// no include option and not git repo discovered (see rust-lang/cargo#7183).
167
167
return self . list_files_walk_except_dot_files_and_dirs ( pkg, & mut filter) ;
@@ -176,51 +176,44 @@ impl<'cfg> PathSource<'cfg> {
176
176
pkg : & Package ,
177
177
root : & Path ,
178
178
filter : & mut dyn FnMut ( & Path , bool ) -> CargoResult < bool > ,
179
- ) -> Option < CargoResult < Vec < PathBuf > > > {
179
+ ) -> CargoResult < Option < Vec < PathBuf > > > {
180
180
let repo = match git2:: Repository :: discover ( root) {
181
181
Ok ( repo) => repo,
182
- Err ( _) => return None ,
183
- } ;
184
- let index = match repo. index ( ) {
185
- Ok ( index) => index,
186
- Err ( err) => {
187
- let e = anyhow:: Error :: new ( err) . context ( format ! (
188
- "failed to open git index at {}" ,
189
- repo. path( ) . display( )
190
- ) ) ;
191
- return Some ( Err ( e) ) ;
192
- }
193
- } ;
194
- let repo_root = match repo. workdir ( ) {
195
- Some ( dir) => dir,
196
- None => {
197
- return Some ( Err ( anyhow:: format_err!(
198
- "did not expect repo at {} to be bare" ,
199
- repo. path( ) . display( )
200
- ) ) )
201
- }
202
- } ;
203
- let repo_relative_path = match root. strip_prefix ( repo_root) {
204
- Ok ( path) => path,
205
- Err ( err) => {
206
- let e = anyhow:: Error :: new ( err) . context ( format ! (
207
- "expected git repo {} to be parent of package {}" ,
208
- repo. path( ) . display( ) ,
209
- root. display( )
210
- ) ) ;
211
- return Some ( Err ( e) ) ;
182
+ Err ( e) => {
183
+ log:: debug!(
184
+ "could not discover git repo at or above {}: {}" ,
185
+ root. display( ) ,
186
+ e
187
+ ) ;
188
+ return Ok ( None ) ;
212
189
}
213
190
} ;
191
+ let index = repo
192
+ . index ( )
193
+ . chain_err ( || format ! ( "failed to open git index at {}" , repo. path( ) . display( ) ) ) ?;
194
+ let repo_root = repo. workdir ( ) . ok_or_else ( || {
195
+ anyhow:: format_err!(
196
+ "did not expect repo at {} to be bare" ,
197
+ repo. path( ) . display( )
198
+ )
199
+ } ) ?;
200
+ let repo_relative_path = root. strip_prefix ( repo_root) . chain_err ( || {
201
+ format ! (
202
+ "expected git repo {} to be parent of package {}" ,
203
+ repo. path( ) . display( ) ,
204
+ root. display( )
205
+ )
206
+ } ) ?;
214
207
// Git requires forward-slashes.
215
208
let repo_safe_path = repo_relative_path
216
209
. join ( "Cargo.toml" )
217
210
. to_string_lossy ( )
218
211
. replace ( '\\' , "/" ) ;
219
212
if index. get_path ( Path :: new ( & repo_safe_path) , 0 ) . is_some ( ) {
220
- return Some ( self . list_files_git ( pkg, & repo, filter) ) ;
213
+ return Ok ( Some ( self . list_files_git ( pkg, & repo, filter) ? ) ) ;
221
214
}
222
215
// Package Cargo.toml is not in git, don't use git to guide our selection.
223
- None
216
+ Ok ( None )
224
217
}
225
218
226
219
fn list_files_git (
0 commit comments