@@ -212,6 +212,8 @@ def find(self, run_args):
212212 repo_name = result ["value" ]
213213 else :
214214 return result
215+ else :
216+ repo_name = repo
215217
216218 # Check if repo_name exists in repos.json
217219 matched_repo_path = None
@@ -220,22 +222,29 @@ def find(self, run_args):
220222 matched_repo_path = repo_obj
221223 break
222224
225+
223226 # Search through self.repos for matching repos
224227 lst = []
225228 for i in self .repos :
226229 if repo_uid and i .meta ['uid' ] == repo_uid :
227230 lst .append (i )
228231 elif repo_name == i .meta ['alias' ]:
229232 lst .append (i )
230- elif utils .is_uid (repo ) and not any (i .meta ['uid' ] == repo_uid for i in self .repos ):
233+
234+
235+ # After loop, check if any match was found
236+ if not lst and not matched_repo_path :
237+ # Determine error message based on input
238+ if utils .is_uid (repo ):
231239 return {"return" : 1 , "error" : f"No repository with UID: '{ repo_uid } ' was found" }
232- elif "," in repo and not matched_repo_path and not any ( i . meta [ 'uid' ] == repo_uid for i in self . repos ) and not any ( i . meta [ 'alias' ] == repo_name for i in self . repos ) :
240+ elif "," in repo and not matched_repo_path :
233241 return {"return" : 1 , "error" : f"No repository with alias: '{ repo_name } ' and UID: '{ repo_uid } ' was found" }
234- elif not matched_repo_path and not any ( i . meta [ 'alias' ] == repo_name for i in self . repos ) and not any ( i . meta [ 'uid' ] == repo_uid for i in self . repos ) :
242+ else :
235243 return {"return" : 1 , "error" : f"No repository with alias: '{ repo_name } ' was found" }
244+
236245
237246 # Append the matched repo path
238- if (len (lst )== 0 ):
247+ if (len (lst )== 0 and matched_repo_path ):
239248 lst .append (matched_repo_path )
240249
241250 return {'return' : 0 , 'list' : lst }
@@ -518,8 +527,27 @@ def rm(self, run_args):
518527 logger .error ("The repository to be removed is not specified" )
519528 return {"return" : 1 , "error" : "The repository to be removed is not specified" }
520529
521- repo_folder_name = run_args ['repo' ]
522- repo_path = os .path .join (self .repos_path , repo_folder_name )
530+ r = self .find (run_args )
531+
532+
533+ if r ['return' ] == 0 :
534+
535+ list_repos = r ['list' ]
536+ if len (list_repos ) > 1 :
537+ return {"return" : 1 , "error" : "Please select a unique repo by repo alias or repo UID to remove" }
538+
539+ repo = list_repos [0 ]
540+ repo_path = repo .path
541+
542+ else :
543+ repo = run_args ['repo' ]
544+ if os .path .exists (repo ):
545+ repo_path = repo
546+ elif os .path .isdir (os .path .join (self .repos_path , repo )):
547+ repo_path = os .path .join (self .repos_path , repo )
548+ else :
549+ return r
550+
523551 repos_file_path = os .path .join (self .repos_path , 'repos.json' )
524552
525553 force_remove = True if run_args .get ('f' ) else False
@@ -530,7 +558,10 @@ def rm_repo(repo_path, repos_file_path, force_remove):
530558 logger .info ("rm command has been called for repo. This would delete the repo folder and unregister the repo from repos.json" )
531559
532560 repo_name = os .path .basename (repo_path )
533- if os .path .exists (repo_path ):
561+ mlc_repos_path = os .path .abspath (os .path .dirname (repos_file_path ))
562+ repo_parent_path = os .path .abspath (os .path .dirname (repo_path ))
563+
564+ if os .path .isdir (repo_path ) and os .path .samefile (mlc_repos_path , repo_parent_path ):
534565 # Check for local changes
535566 status_command = ['git' , '-C' , repo_path , 'status' , '--porcelain' , '--untracked-files=no' ]
536567 local_changes = subprocess .run (status_command , capture_output = True , text = True )
@@ -554,7 +585,7 @@ def rm_repo(repo_path, repos_file_path, force_remove):
554585
555586
556587 else :
557- logger .warning (f"Repo { repo_name } was not found in the repo folder. repos.json will be checked for any corrupted entry . If any, that will be removed." )
588+ logger .warning (f"Repo { repo_name } was not found in the repo folder. repos.json will be checked for external paths . If any, that will be removed." )
558589 unregister_repo (repo_path , repos_file_path )
559590
560591 return {"return" : 0 }
0 commit comments