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".
This commit is contained in:
21
emsdk.py
21
emsdk.py
@@ -788,21 +788,21 @@ def git_recent_commits(repo_path, n=20):
|
||||
return []
|
||||
|
||||
|
||||
def git_clone(url, dstpath):
|
||||
def git_clone(url, dstpath, branch):
|
||||
debug_print('git_clone(url=' + url + ', dstpath=' + dstpath + ')')
|
||||
if os.path.isdir(os.path.join(dstpath, '.git')):
|
||||
debug_print("Repository '" + url + "' already cloned to directory '" + dstpath + "', skipping.")
|
||||
return True
|
||||
mkdir_p(dstpath)
|
||||
git_clone_args = []
|
||||
git_clone_args = ['--recurse-submodules', '--branch', branch] # Do not check out a branch (installer will issue a checkout command right after)
|
||||
if GIT_CLONE_SHALLOW:
|
||||
git_clone_args += ['--depth', '1']
|
||||
print('Cloning from ' + url + '...')
|
||||
return run([GIT(), 'clone', '--recurse-submodules'] + git_clone_args + [url, dstpath]) == 0
|
||||
return run([GIT(), 'clone'] + git_clone_args + [url, dstpath]) == 0
|
||||
|
||||
|
||||
def git_checkout_and_pull(repo_path, branch_or_tag):
|
||||
debug_print('git_checkout_and_pull(repo_path=' + repo_path + ', branch/tag=' + branch_or_tag + ')')
|
||||
def git_pull(repo_path, branch_or_tag):
|
||||
debug_print('git_pull(repo_path=' + repo_path + ', branch/tag=' + branch_or_tag + ')')
|
||||
ret = run([GIT(), 'fetch', '--quiet', 'origin'], repo_path)
|
||||
if ret != 0:
|
||||
return False
|
||||
@@ -835,11 +835,12 @@ def git_checkout_and_pull(repo_path, branch_or_tag):
|
||||
|
||||
def git_clone_checkout_and_pull(url, dstpath, branch):
|
||||
debug_print('git_clone_checkout_and_pull(url=' + url + ', dstpath=' + dstpath + ', branch=' + branch + ')')
|
||||
success = git_clone(url, dstpath)
|
||||
if not success:
|
||||
return False
|
||||
success = git_checkout_and_pull(dstpath, branch)
|
||||
return success
|
||||
|
||||
# If the repository has already been cloned before, issue a pull operation. Otherwise do a new clone.
|
||||
if os.path.isdir(os.path.join(dstpath, '.git')):
|
||||
return git_pull(dstpath, branch)
|
||||
else:
|
||||
return git_clone(url, dstpath, branch)
|
||||
|
||||
|
||||
# Each tool can have its own build type, or it can be overridden on the command
|
||||
|
||||
Reference in New Issue
Block a user