Skip to content

Commit

Permalink
Merge pull request #4310 from boegel/fix_get_source_tarball_from_git
Browse files Browse the repository at this point in the history
disable trace output for commands run in `get_source_tarball_from_git`
  • Loading branch information
branfosj committed Aug 7, 2023
2 parents 50214e7 + 244d068 commit 9e78ca3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ def get_source_tarball_from_git(filename, targetdir, git_config):

tmpdir = tempfile.mkdtemp()
cwd = change_dir(tmpdir)
run.run_cmd(' '.join(clone_cmd), log_all=True, simple=True, regexp=False)
run.run_cmd(' '.join(clone_cmd), log_all=True, simple=True, regexp=False, trace=False)

# If the clone is done into a specified name, change repo_name
if clone_into:
Expand All @@ -2662,14 +2662,14 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
if recursive:
checkout_cmd.extend(['&&', 'git', 'submodule', 'update', '--init', '--recursive'])

run.run_cmd(' '.join(checkout_cmd), log_all=True, simple=True, regexp=False, path=repo_name)
run.run_cmd(' '.join(checkout_cmd), log_all=True, simple=True, regexp=False, path=repo_name, trace=False)

elif not build_option('extended_dry_run'):
# If we wanted to get a tag make sure we actually got a tag and not a branch with the same name
# This doesn't make sense in dry-run mode as we don't have anything to check
cmd = 'git describe --exact-match --tags HEAD'
# Note: Disable logging to also disable the error handling in run_cmd
(out, ec) = run.run_cmd(cmd, log_ok=False, log_all=False, regexp=False, path=repo_name)
(out, ec) = run.run_cmd(cmd, log_ok=False, log_all=False, regexp=False, path=repo_name, trace=False)
if ec != 0 or tag not in out.splitlines():
print_warning('Tag %s was not downloaded in the first try due to %s/%s containing a branch'
' with the same name. You might want to alert the maintainers of %s about that issue.',
Expand All @@ -2688,14 +2688,14 @@ def get_source_tarball_from_git(filename, targetdir, git_config):
if recursive:
cmds.append('git submodule update --init --recursive')
for cmd in cmds:
run.run_cmd(cmd, log_all=True, simple=True, regexp=False, path=repo_name)
run.run_cmd(cmd, log_all=True, simple=True, regexp=False, path=repo_name, trace=False)

# create an archive and delete the git repo directory
if keep_git_dir:
tar_cmd = ['tar', 'cfvz', targetpath, repo_name]
else:
tar_cmd = ['tar', 'cfvz', targetpath, '--exclude', '.git', repo_name]
run.run_cmd(' '.join(tar_cmd), log_all=True, simple=True, regexp=False)
run.run_cmd(' '.join(tar_cmd), log_all=True, simple=True, regexp=False, trace=False)

# cleanup (repo_name dir does not exist in dry run mode)
change_dir(cwd)
Expand Down
32 changes: 17 additions & 15 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ def test_diff_files(self):
self.assertTrue(regex.search(res), "Pattern '%s' found in: %s" % (regex.pattern, res))

@requires_github_access()
def test_get_source_tarball_from_git(self):
def test_github_get_source_tarball_from_git(self):
"""Test get_source_tarball_from_git function."""

target_dir = os.path.join(self.test_prefix, 'target')
Expand Down Expand Up @@ -2790,37 +2790,37 @@ def run_check():
git_repo = {'git_repo': 'git@github.com:easybuilders/testrepository.git'} # Just to make the below shorter
expected = '\n'.join([
r' running command "git clone --depth 1 --branch tag_for_tests %(git_repo)s"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
]) % git_repo
run_check()

git_config['clone_into'] = 'test123'
expected = '\n'.join([
r' running command "git clone --depth 1 --branch tag_for_tests %(git_repo)s test123"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git test123"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
]) % git_repo
run_check()
del git_config['clone_into']

git_config['recursive'] = True
expected = '\n'.join([
r' running command "git clone --depth 1 --branch tag_for_tests --recursive %(git_repo)s"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
]) % git_repo
run_check()

git_config['keep_git_dir'] = True
expected = '\n'.join([
r' running command "git clone --branch tag_for_tests --recursive %(git_repo)s"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
r' running command "tar cfvz .*/target/test.tar.gz testrepository"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
]) % git_repo
run_check()
del git_config['keep_git_dir']
Expand All @@ -2829,22 +2829,22 @@ def run_check():
git_config['commit'] = '8456f86'
expected = '\n'.join([
r' running command "git clone --no-checkout %(git_repo)s"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
r' running command "git checkout 8456f86 && git submodule update --init --recursive"',
r" \(in testrepository\)",
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
]) % git_repo
run_check()

del git_config['recursive']
expected = '\n'.join([
r' running command "git clone --no-checkout %(git_repo)s"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
r' running command "git checkout 8456f86"',
r" \(in testrepository\)",
r' running command "tar cfvz .*/target/test.tar.gz --exclude .git testrepository"',
r" \(in .*/tmp.*\)",
r" \(in /.*\)",
]) % git_repo
run_check()

Expand All @@ -2866,7 +2866,8 @@ def run_check():
self.assertEqual(os.listdir(target_dir), ['test.tar.gz'])
# Check that we indeed downloaded the right tag
extracted_dir = tempfile.mkdtemp(prefix='extracted_dir')
extracted_repo_dir = ft.extract_file(test_file, extracted_dir, change_into_dir=False)
with self.mocked_stdout_stderr():
extracted_repo_dir = ft.extract_file(test_file, extracted_dir, change_into_dir=False)
self.assertTrue(os.path.isfile(os.path.join(extracted_repo_dir, 'this-is-a-branch.txt')))
os.remove(test_file)

Expand All @@ -2880,7 +2881,8 @@ def run_check():
self.assertTrue(os.path.isfile(test_file))
# Check that we indeed downloaded the tag and not the branch
extracted_dir = tempfile.mkdtemp(prefix='extracted_dir')
extracted_repo_dir = ft.extract_file(test_file, extracted_dir, change_into_dir=False)
with self.mocked_stdout_stderr():
extracted_repo_dir = ft.extract_file(test_file, extracted_dir, change_into_dir=False)
self.assertTrue(os.path.isfile(os.path.join(extracted_repo_dir, 'this-is-a-tag.txt')))

del git_config['tag']
Expand Down

0 comments on commit 9e78ca3

Please sign in to comment.