Skip to content

Commit 7d5e3f3

Browse files
authored
Git clone desired target branch directly (#1030)
When doing a git clone of a branch, instead of doing a general git clone that first would check out the default (main/master) branch and then later doing a checkout to switch to the target branch, instead specify the `--branch` option to the clone command line to immediately clone and checkout the desired final branch. This helps first checkout runtime performance on CIs, especially when using shallow clones (GIT_CLONE_SHALLOW option). Also this sidesteps a really odd git clone issue we are currently seeing in our CI, where it is unable to `checkout` the googletest submodule in binaryen, but would fail saying "path not found".
1 parent 051d745 commit 7d5e3f3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

emsdk.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -788,21 +788,21 @@ def git_recent_commits(repo_path, n=20):
788788
return []
789789

790790

791-
def git_clone(url, dstpath):
791+
def git_clone(url, dstpath, branch):
792792
debug_print('git_clone(url=' + url + ', dstpath=' + dstpath + ')')
793793
if os.path.isdir(os.path.join(dstpath, '.git')):
794794
debug_print("Repository '" + url + "' already cloned to directory '" + dstpath + "', skipping.")
795795
return True
796796
mkdir_p(dstpath)
797-
git_clone_args = []
797+
git_clone_args = ['--recurse-submodules', '--branch', branch] # Do not check out a branch (installer will issue a checkout command right after)
798798
if GIT_CLONE_SHALLOW:
799799
git_clone_args += ['--depth', '1']
800800
print('Cloning from ' + url + '...')
801-
return run([GIT(), 'clone', '--recurse-submodules'] + git_clone_args + [url, dstpath]) == 0
801+
return run([GIT(), 'clone'] + git_clone_args + [url, dstpath]) == 0
802802

803803

804-
def git_checkout_and_pull(repo_path, branch_or_tag):
805-
debug_print('git_checkout_and_pull(repo_path=' + repo_path + ', branch/tag=' + branch_or_tag + ')')
804+
def git_pull(repo_path, branch_or_tag):
805+
debug_print('git_pull(repo_path=' + repo_path + ', branch/tag=' + branch_or_tag + ')')
806806
ret = run([GIT(), 'fetch', '--quiet', 'origin'], repo_path)
807807
if ret != 0:
808808
return False
@@ -835,11 +835,12 @@ def git_checkout_and_pull(repo_path, branch_or_tag):
835835

836836
def git_clone_checkout_and_pull(url, dstpath, branch):
837837
debug_print('git_clone_checkout_and_pull(url=' + url + ', dstpath=' + dstpath + ', branch=' + branch + ')')
838-
success = git_clone(url, dstpath)
839-
if not success:
840-
return False
841-
success = git_checkout_and_pull(dstpath, branch)
842-
return success
838+
839+
# If the repository has already been cloned before, issue a pull operation. Otherwise do a new clone.
840+
if os.path.isdir(os.path.join(dstpath, '.git')):
841+
return git_pull(dstpath, branch)
842+
else:
843+
return git_clone(url, dstpath, branch)
843844

844845

845846
# Each tool can have its own build type, or it can be overridden on the command

0 commit comments

Comments
 (0)