@@ -334,7 +334,7 @@ def init_command():
334334 return Command ().command (_init )
335335
336336
337- def fetch_template_from_git (source , ref = "master" , tempdir = None ):
337+ def fetch_template_from_git (source , ref = None , tempdir = None ):
338338 """Fetch the template from a git repository and checkout the relevant data.
339339
340340 :param source: url or full path of the templates repository
@@ -351,17 +351,22 @@ def fetch_template_from_git(source, ref="master", tempdir=None):
351351 except git .exc .GitCommandError as e :
352352 raise errors .GitError ("Cannot clone repo from {0}" .format (source )) from e
353353
354- try :
355- # fetch ref and set the HEAD
356- template_repo .remotes .origin .fetch (ref )
354+ if ref :
357355 try :
358- template_repo .head .reset (template_repo .commit (ref ))
359- except git .exc .BadName :
360- ref = "origin/{0}" .format (ref )
361- template_repo .head .reset (template_repo .commit (ref ))
356+ # fetch ref and set the HEAD
357+ template_repo .remotes .origin .fetch (ref )
358+ try :
359+ template_repo .head .reset (template_repo .commit (ref ))
360+ except git .exc .BadName :
361+ ref = "origin/{0}" .format (ref )
362+ template_repo .head .reset (template_repo .commit (ref ))
363+ git_repo = git .Git (str (tempdir ))
364+ except git .exc .GitCommandError as e :
365+ raise errors .GitError ("Cannot fetch and checkout reference {0}" .format (ref )) from e
366+ else :
367+ template_repo .remotes .origin .fetch ()
368+ template_repo .head .reset (template_repo .commit ())
362369 git_repo = git .Git (str (tempdir ))
363- except git .exc .GitCommandError as e :
364- raise errors .GitError ("Cannot fetch and checkout reference {0}" .format (ref )) from e
365370
366371 # checkout the manifest
367372 try :
@@ -380,14 +385,17 @@ def fetch_template(template_source, template_ref):
380385 :return: tuple of (template manifest, template folder, template source, template version)
381386 """
382387 if template_source and template_source != "renku" :
383- communication .echo ("Fetching template from {0}@{1}... " .format (template_source , template_ref ))
388+ communication .echo ("Fetching template from {0}@{1}... " .format (template_source , template_ref or "" ))
384389 template_folder = Path (mkdtemp ())
385390 _ , template_version = fetch_template_from_git (template_source , template_ref , template_folder )
386391 template_manifest = read_template_manifest (template_folder , checkout = True )
387392 communication .echo ("OK" )
388393 else :
389394 from renku import __version__
390395
396+ if template_ref :
397+ raise errors .ParameterError ("Templates included in renku don't support specifying a template_ref" )
398+
391399 template_folder = Path (pkg_resources .resource_filename ("renku" , "templates" ))
392400 template_manifest = read_template_manifest (template_folder )
393401 template_source = "renku"
0 commit comments