From: Jochen Sprickerhof Date: Tue, 30 Jan 2024 08:01:43 +0100 Subject: Drop distutils usage (and assume non ancient git version) --- src/vcstools/git.py | 15 +++++++-------- test/test_git.py | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/vcstools/git.py b/src/vcstools/git.py index abfe690..3a18004 100644 --- a/src/vcstools/git.py +++ b/src/vcstools/git.py @@ -60,7 +60,6 @@ import shutil import tempfile import gzip import dateutil.parser # For parsing date strings -from distutils.version import LooseVersion import logging from vcstools.vcs_base import VcsClientBase, VcsError @@ -146,8 +145,8 @@ class GitClient(VcsClientBase): metadict = {} try: version = _get_git_version() - resetkeep = LooseVersion(version) >= LooseVersion('1.7.1') - submodules = LooseVersion(version) > LooseVersion('1.7') + resetkeep = True + submodules = True metadict["features"] = "'reset --keep': %s, submodules: %s" % (resetkeep, submodules) except VcsError: version = "No git installed" @@ -188,7 +187,7 @@ class GitClient(VcsClientBase): cmd = 'git clone' if shallow: cmd += ' --depth 1' - if LooseVersion(self.gitversion) >= LooseVersion('1.7.10'): + if True: cmd += ' --no-single-branch' if version is None: # quicker than using _do_update, but undesired when switching branches next @@ -222,7 +221,7 @@ class GitClient(VcsClientBase): def _update_submodules(self, verbose=False, timeout=None): # update submodules ( and init if necessary ). - if LooseVersion(self.gitversion) > LooseVersion('1.7'): + if True: cmd = "git submodule update --init --recursive" value, _, _ = run_shell_command(cmd, shell=True, @@ -449,7 +448,7 @@ class GitClient(VcsClientBase): cmd = "git diff HEAD --src-prefix=%s/ --dst-prefix=%s/ ." % \ (sanitized(rel_path), sanitized(rel_path)) _, response, _ = run_shell_command(cmd, shell=True, cwd=self._path) - if LooseVersion(self.gitversion) > LooseVersion('1.7'): + if True: cmd = 'git submodule foreach --recursive git diff HEAD' _, output, _ = run_shell_command(cmd, shell=True, cwd=self._path) response += _git_diff_path_submodule_change(output, rel_path) @@ -518,7 +517,7 @@ class GitClient(VcsClientBase): response_processed += '%s%s/%s\n' % (line[0:3], rel_path, line[3:]) - if LooseVersion(self.gitversion) > LooseVersion('1.7'): + if True: if not untracked: status_flag += " -uno" command = "git submodule foreach --recursive 'git status {0}'".format(status_flag) @@ -857,7 +856,7 @@ class GitClient(VcsClientBase): print("Rebasing repository") # Rebase, do not pull, because somebody could have # commited in the meantime. - if LooseVersion(self.gitversion) >= LooseVersion('1.7.1'): + if True: # --keep allows to rebase even with local changes, as long as # local changes are not in files that change between versions cmd = "git reset --keep remotes/%s/%s" % (default_remote, branch_parent) diff --git a/test/test_git.py b/test/test_git.py index 997d851..5b506ea 100644 --- a/test/test_git.py +++ b/test/test_git.py @@ -43,7 +43,6 @@ import types import threading import time -from distutils.version import LooseVersion from vcstools import GitClient from vcstools.vcs_base import VcsError @@ -253,7 +252,7 @@ class GitClientTest(GitClientTestSetups): self.assertEqual(client._get_branch_parent(), ("master", "origin")) po = subprocess.Popen("git log --pretty=format:%H", shell=True, cwd=self.local_path, stdout=subprocess.PIPE) log = po.stdout.read().decode('UTF-8').strip().splitlines() - if LooseVersion(client.gitversion) >= LooseVersion('1.8.2'): + if True: # shallow only contains last commit self.assertEqual(1, len(log), log) else: