File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,21 @@ pub fn init() -> Result<()> {
2929 bail ! ( RUSTLINGS_DIR_ALREADY_EXISTS_ERR ) ;
3030 }
3131
32+ let is_inside_vcs_repository = ' detect_repo: {
33+ let Ok ( mut dir) = std:: env:: current_dir ( ) else {
34+ break ' detect_repo false ;
35+ } ;
36+ loop {
37+ if dir. join ( ".git" ) . exists ( ) || dir. join ( ".jj" ) . exists ( ) {
38+ break ' detect_repo true ;
39+ }
40+ match dir. parent ( ) {
41+ Some ( parent) => dir = parent. into ( ) ,
42+ None => break ' detect_repo false ,
43+ }
44+ }
45+ } ;
46+
3247 let locate_project_output = Command :: new ( "cargo" )
3348 . arg ( "locate-project" )
3449 . arg ( "-q" )
@@ -59,7 +74,7 @@ pub fn init() -> Result<()> {
5974 }
6075
6176 let mut stdout = io:: stdout ( ) . lock ( ) ;
62- let mut init_git = true ;
77+ let mut init_git = !is_inside_vcs_repository ;
6378
6479 if locate_project_output. status . success ( ) {
6580 if Path :: new ( "exercises" ) . exists ( ) && Path :: new ( "solutions" ) . exists ( ) {
You can’t perform that action at this time.
0 commit comments