@@ -249,6 +249,35 @@ def pull_again(self, repo: Optional[str]=None, branch: Optional[str]=None) -> No
249
249
except KeyError :
250
250
pass
251
251
252
+ def get_reference_repository (self , reference : Optional [Path ], repo : str ) -> Optional [Path ]:
253
+ """
254
+ Returns a repository to use in clone command, if there is one to be referenced.
255
+ Either provided by the user of generated from already cloned branches (master is preferred).
256
+
257
+ :param reference: Path to a local repository provided by the user or None.
258
+ :param repo: Reference for which remote repository.
259
+ """
260
+ if reference is not None :
261
+ return reference .absolute ()
262
+
263
+ repo_path = self .get_path_to_repo (repo )
264
+
265
+ if not repo_path .exists ():
266
+ return None
267
+
268
+ master = repo_path / "master"
269
+
270
+ if master .exists () and master .is_dir ():
271
+ return master
272
+
273
+ for existing_branch in repo_path .iterdir ():
274
+ if not existing_branch .is_dir ():
275
+ continue
276
+
277
+ return existing_branch .resolve ()
278
+
279
+ return None
280
+
252
281
def _pull (self , * , repo_path : Path = None , git_repo : Repo = None , repo : str = None , branch : str = None ,
253
282
depth : Optional [int ]= None ,
254
283
reference : Optional [Path ]= None
@@ -271,8 +300,10 @@ def _pull(self, *, repo_path: Path=None, git_repo: Repo=None, repo: str=None, br
271
300
if depth is not None :
272
301
kwargs ["depth" ] = depth
273
302
303
+ reference = self .get_reference_repository (reference , repo )
304
+
274
305
if reference is not None :
275
- kwargs ["reference-if-able" ] = str (reference . absolute () )
306
+ kwargs ["reference-if-able" ] = str (reference )
276
307
kwargs ["dissociate" ] = True
277
308
278
309
try :
0 commit comments