@@ -41,7 +41,8 @@ def is_local_clone(folder: Union[str, Path], remote_url: str):
4141
4242 # Remove token for the test with remotes.
4343 remote_url = re .sub (r"https://.*@" , "https://" , remote_url )
44- return remote_url in remotes .split ()
44+ remotes = [re .sub (r"https://.*@" , "https://" , remote ) for remote in remotes .split ()]
45+ return remote_url in remotes
4546
4647
4748class Repository :
@@ -163,6 +164,9 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non
163164 repo_url = repo_url .replace (
164165 "https://" , f"https://user:{ huggingface_token } @"
165166 )
167+
168+ # For error messages, it's cleaner to show the repo url without the token.
169+ clean_repo_url = re .sub (r"https://.*@" , "https://" , repo_url )
166170 try :
167171 subprocess .run (
168172 "git lfs install" .split (),
@@ -174,7 +178,7 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non
174178
175179 # checks if repository is initialized in a empty repository or in one with files
176180 if len (os .listdir (self .local_dir )) == 0 :
177- logger .debug (f"Cloning { repo_url } into local empty directory." )
181+ logger .debug (f"Cloning { clean_repo_url } into local empty directory." )
178182 subprocess .run (
179183 ["git" , "clone" , repo_url , "." ],
180184 stderr = subprocess .PIPE ,
@@ -190,7 +194,7 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non
190194 if in_repository :
191195 if is_local_clone (self .local_dir , repo_url ):
192196 logger .debug (
193- f"{ self .local_dir } is already a clone of { repo_url } . Make sure you pull the latest"
197+ f"{ self .local_dir } is already a clone of { clean_repo_url } . Make sure you pull the latest"
194198 "changes with `repo.git_pull()`."
195199 )
196200 else :
@@ -203,11 +207,14 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non
203207 )
204208
205209 error_msg = (
206- f"Tried to clone { repo_url } in an unrelated git repository.\n If you believe this is an "
207- f"error, please add a remote with the following URL: { repo_url } ."
210+ f"Tried to clone { clean_repo_url } in an unrelated git repository.\n If you believe this is "
211+ f"an error, please add a remote with the following URL: { clean_repo_url } ."
208212 )
209213 if output .returncode == 0 :
210- error_msg += f"\n Local path has its origin defined as: { output .stdout } "
214+ clean_local_remote_url = re .sub (
215+ r"https://.*@" , "https://" , output .stdout
216+ )
217+ error_msg += f"\n Local path has its origin defined as: { clean_local_remote_url } "
211218
212219 raise EnvironmentError (error_msg )
213220
0 commit comments