Skip to content

Commit 956fa9c

Browse files
committed
Speed up git checkouts
Use shallow checkouts if .git folder is not required Don't download submodules if we do that again for a potentially other version
1 parent 07b671a commit 956fa9c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

easybuild/tools/filetools.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,11 +2471,17 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
24712471
# compose 'git clone' command, and run it
24722472
clone_cmd = ['git', 'clone']
24732473

2474+
if not keep_git_dir:
2475+
# Speed up cloning by only fetching the most recent commit, not the whole history
2476+
# When we don't want to keep the .git folder there won't be a difference in the result
2477+
clone_cmd.extend(['--depth', '1'])
2478+
24742479
if tag:
24752480
clone_cmd.extend(['--branch', 'refs/tags/' + tag])
2476-
2477-
if recursive:
2478-
clone_cmd.append('--recursive')
2481+
if recursive:
2482+
clone_cmd.append('--recursive')
2483+
else:
2484+
clone_cmd.append('--no-checkout') # We do that manually below
24792485

24802486
clone_cmd.append('%s/%s.git' % (url, repo_name))
24812487

test/framework/filetools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ def run_check():
25792579
'tag': 'tag_for_tests',
25802580
}
25812581
expected = '\n'.join([
2582-
r' running command "git clone --branch refs/tags/tag_for_tests [email protected]:easybuilders/testrepository.git"',
2582+
r' running command "git clone --depth 1 --branch refs/tags/tag_for_tests [email protected]:easybuilders/testrepository.git"',
25832583
r" \(in .*/tmp.*\)",
25842584
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
25852585
r" \(in .*/tmp.*\)",
@@ -2588,7 +2588,7 @@ def run_check():
25882588

25892589
git_config['recursive'] = True
25902590
expected = '\n'.join([
2591-
r' running command "git clone --branch refs/tags/tag_for_tests --recursive [email protected]:easybuilders/testrepository.git"',
2591+
r' running command "git clone --depth 1 --branch refs/tags/tag_for_tests --recursive [email protected]:easybuilders/testrepository.git"',
25922592
r" \(in .*/tmp.*\)",
25932593
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
25942594
r" \(in .*/tmp.*\)",
@@ -2608,7 +2608,7 @@ def run_check():
26082608
del git_config['tag']
26092609
git_config['commit'] = '8456f86'
26102610
expected = '\n'.join([
2611-
r' running command "git clone --recursive [email protected]:easybuilders/testrepository.git"',
2611+
r' running command "git clone --depth 1 --no-checkout [email protected]:easybuilders/testrepository.git"',
26122612
r" \(in .*/tmp.*\)",
26132613
r' running command "git checkout 8456f86 && git submodule update --init --recursive"',
26142614
r" \(in testrepository\)",
@@ -2619,7 +2619,7 @@ def run_check():
26192619

26202620
del git_config['recursive']
26212621
expected = '\n'.join([
2622-
r' running command "git clone [email protected]:easybuilders/testrepository.git"',
2622+
r' running command "git clone --depth 1 --no-checkout [email protected]:easybuilders/testrepository.git"',
26232623
r" \(in .*/tmp.*\)",
26242624
r' running command "git checkout 8456f86"',
26252625
r" \(in testrepository\)",

0 commit comments

Comments
 (0)