Skip to content

Commit 8330c80

Browse files
Simplify git client checkout_repository method.
Signed-off-by: Leander Stephen D'Souza <[email protected]>
1 parent 09dd985 commit 8330c80

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

vcs2l/clients/git.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import subprocess
3-
import tempfile
43
from shutil import which
54

65
from vcs2l.clients.vcs_base import VcsClientBase
@@ -789,40 +788,17 @@ def export_repository(self, version, basepath):
789788
return False
790789

791790
self._check_executable()
792-
filepath = '{0}.tar.gz'.format(basepath)
793-
794-
# If current version matches export version and no local changes, export directly
795-
current_sha = self._get_current_version()
796-
export_sha = self._get_version_sha(version) if version else current_sha
797-
if current_sha == export_sha and self._has_no_local_changes():
798-
cmd = [
799-
GitClient._executable,
800-
'archive',
801-
'--format=tar.gz',
802-
'--output={}'.format(filepath),
803-
version or 'HEAD',
804-
]
805-
result = self._run_command(cmd)
806-
if result['returncode'] == 0:
807-
return filepath
808-
809-
# Otherwise use temp directory approach
810-
tmpd_path = tempfile.mkdtemp()
811-
try:
812-
tmpgit = GitClient(tmpd_path)
813-
if tmpgit.checkout(self.path, version=version, shallow=False):
814-
cmd = [
815-
GitClient._executable,
816-
'archive',
817-
'--format=tar.gz',
818-
'--output={}'.format(filepath),
819-
version or 'HEAD',
820-
]
821-
result = tmpgit._run_command(cmd)
822-
return filepath if result['returncode'] == 0 else False
823-
return False
824-
finally:
825-
rmtree(tmpd_path)
791+
filepath = f'{basepath}.tar.gz'
792+
793+
cmd = [
794+
GitClient._executable,
795+
'archive',
796+
'--format=tar.gz',
797+
f'--output={filepath}',
798+
version or 'HEAD',
799+
]
800+
result = self._run_command(cmd)
801+
return filepath if result['returncode'] == 0 else False
826802

827803
def checkout(self, url, version=None, verbose=False, shallow=False, timeout=None):
828804
"""Clone a git repository to the specified path and checkout a specific version."""

0 commit comments

Comments
 (0)