diff --git a/autosubmit/config/config_common.py b/autosubmit/config/config_common.py index 3f872f17b3021f42e3fc629d8bc11a6082305fe0..c0d553567638f9839f273cff97c4824227a259d6 100644 --- a/autosubmit/config/config_common.py +++ b/autosubmit/config/config_common.py @@ -675,7 +675,14 @@ class AutosubmitConfig(object): """ return ' '.join(self._exp_parser.get_option('git', 'PROJECT_SUBMODULES','').split()).split() - + def get_fetch_single_branch(self): + """ + Returns fetch single branch from experiment's config file + Default is -single-branch + :return: fetch_single_branch(Y/N) + :rtype: boolean + """ + return self._exp_parser.get_option('git', 'FETCH_SINGLE_BRANCH', 'False').lower() def get_project_destination(self): """ Returns git commit from experiment's config file diff --git a/autosubmit/config/files/expdef.conf b/autosubmit/config/files/expdef.conf index 96e2b6fd32c5c2e5153fba6c82367f2677f7210f..8a963977465ac4c9d1b7ae3c7c6f40d411c98d17 100644 --- a/autosubmit/config/files/expdef.conf +++ b/autosubmit/config/files/expdef.conf @@ -48,6 +48,9 @@ PROJECT_BRANCH = PROJECT_COMMIT = # type = STRING, default = leave empty and will load all submodules, help = loadThisSubmodule alsoloadthis anotherLoad ... PROJECT_SUBMODULES = +# type = STRING, default = leave empty and will clone only a single branch, help = true,false +FETCH_SINGLE_BRANCH = false + # If PROJECT_TYPE is not svn, no need to change [svn] # type = STRING, help = 'https://svn.ec-earth.org/ecearth3' diff --git a/autosubmit/git/autosubmit_git.py b/autosubmit/git/autosubmit_git.py index 594642c0d7cdee62e53ae892b87a3106b44528f7..56acd975292ecca4d429a68d032968286147b5e6 100644 --- a/autosubmit/git/autosubmit_git.py +++ b/autosubmit/git/autosubmit_git.py @@ -129,6 +129,11 @@ class AutosubmitGit: git_project_branch = as_conf.get_git_project_branch() git_project_commit = as_conf.get_git_project_commit() git_project_submodules = as_conf.get_submodules_list() + if as_conf.get_fetch_single_branch() != "true": + git_single_branch = False + else: + git_single_branch = True + project_destination = as_conf.get_project_destination() project_path = os.path.join(BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) git_path = as_conf.get_project_dir() @@ -146,8 +151,13 @@ class AutosubmitGit: if git_project_commit: Log.info("Fetching {0} into {1}", git_project_commit + " " + git_project_origin, project_path) try: - - command = "cd {0}; git clone {1} {4}; cd {2}; git checkout {3};".format(project_path, + if git_single_branch: + command = "cd {0}; git clone {1} {4}; cd {2}; git checkout {3};".format(project_path, + git_project_origin, git_path, + git_project_commit, + project_destination) + else: + command = "cd {0}; git clone {1} {4}; cd {2}; git checkout {3};".format(project_path, git_project_origin, git_path, git_project_commit, project_destination) @@ -168,18 +178,33 @@ class AutosubmitGit: Log.info("Cloning {0} into {1}", git_project_branch + " " + git_project_origin, project_path) try: command = "cd {0}; ".format(project_path) + if git_project_submodules.__len__() <= 0: - command += " git clone --recursive -b {0} {1} {2}".format(git_project_branch, git_project_origin, - project_destination) + if not git_single_branch: + command += " git clone --recursive -b {0} {1} {2}".format(git_project_branch, git_project_origin, + project_destination) + else: + command += " git clone --single-branch --depth=1 --recursive -b {0} {1} {2}".format(git_project_branch, git_project_origin, + project_destination) else: - command += " git clone -b {0} {1} {2};".format(git_project_branch, git_project_origin, + if not git_single_branch: + command += " git clone -b {0} {1} {2};".format(git_project_branch, git_project_origin, project_destination) + else: + command += " git clone --single-branch --depth=1 -b {0} {1} {2};".format(git_project_branch, + git_project_origin, + project_destination) + command += " cd {0}; git submodule init;".format(project_destination) for submodule in git_project_submodules: - command += " git submodule update {0};".format(submodule) - + command += " git submodule update {0};".format(submodule) + Log.debug('{0}', command) output = subprocess.check_output(command, shell=True) - Log.debug('{0}:{1}', command, output) + #Log.debug('{0}:{1}', command, output) + #command " git config --file .gitmodules --get-regexp path | awk '{ print $2 }' " you can change path per url + #https://stackoverflow.com/questions/27188899/shallow-clone-with-submodules-in-git-how-to-use-pointed-commits-and-not-latest + #../../svn/ecearth-mirror.git + # git clone -n --depth=1 --separate-git-dir sources https://earth.bsc.es/svn/ecearth-mirror.git sources except subprocess.CalledProcessError: Log.error("Can not clone {0} into {1}", git_project_branch + " " + git_project_origin, project_path) shutil.rmtree(project_path)