3434from git import GitCommandError , GitError , Repo
3535
3636from renku .core import errors
37+ from renku .core .management .clone import clone
3738from renku .core .management .config import RENKU_HOME
3839from renku .core .models .datasets import Dataset , DatasetFile , DatasetTag
3940from renku .core .models .git import GitURL
@@ -755,9 +756,13 @@ def checkout(repo, ref):
755756 repo = Repo (str (repo_path ))
756757 if repo .remotes .origin .url == url :
757758 try :
758- repo .git .fetch ()
759+ repo .git .fetch (all = True )
759760 repo .git .checkout (ref )
760- repo .git .pull ()
761+ try :
762+ repo .git .pull ()
763+ except GitError :
764+ # When ref is not a branch, an error is thrown
765+ pass
761766 except GitError :
762767 # ignore the error and try re-cloning
763768 pass
@@ -772,25 +777,17 @@ def checkout(repo, ref):
772777 format (repo_path )
773778 )
774779
780+ repo = clone (url , path = str (repo_path ), install_githooks = False )
781+
782+ # Because the name of the default branch is not always 'master', we
783+ # create an alias of the default branch when cloning the repo. It
784+ # is used to refer to the default branch later.
785+ renku_ref = 'refs/heads/' + RENKU_BRANCH
775786 try :
776- os .environ ['GIT_LFS_SKIP_SMUDGE' ] = '1'
777- repo = Repo .clone_from (url , str (repo_path ), recursive = True )
778- # Because the name of the default branch is not always 'master', we
779- # create an alias of the default branch when cloning the repo. It
780- # is used to refer to the default branch later.
781- renku_ref = 'refs/heads/' + RENKU_BRANCH
782787 repo .git .execute ([
783788 'git' , 'symbolic-ref' , renku_ref , repo .head .reference .path
784789 ])
785790 checkout (repo , ref )
786- # Disable Git LFS smudge filter
787- repo .git .execute (
788- command = [
789- 'git' , 'lfs' , 'install' , '--local' , '--skip-smudge' ,
790- '--force'
791- ],
792- with_exceptions = False
793- )
794791 except GitCommandError as e :
795792 raise errors .GitError (
796793 'Cannot clone remote Git repo: {}' .format (url )
0 commit comments