|
31 | 31 | import sys |
32 | 32 | import zipfile |
33 | 33 |
|
34 | | -from distutils.version import LooseVersion |
35 | | - |
36 | 34 | __version__ = "0.21.5" |
37 | 35 |
|
38 | 36 | is_windows = os.name == "nt" |
@@ -235,16 +233,24 @@ def write_dir(path, d, overwrite, zip_path): |
235 | 233 | write_dir(next_path, d, overwrite, entry) |
236 | 234 |
|
237 | 235 |
|
238 | | -def git_init(cwd): |
239 | | - branch = "" |
| 236 | +def determine_git_version(): |
240 | 237 | git_version_out = \ |
241 | 238 | subprocess.run("git --version", shell=True, capture_output=True) |
242 | 239 | if git_version_out.returncode != 0: |
| 240 | + return None |
| 241 | + git_version_str = str(git_version_out.stdout[12:], sys.stdout.encoding) |
| 242 | + git_version = list(map(int, git_version_str.rstrip().split(".")[:3])) |
| 243 | + if len(git_version) < 3: |
| 244 | + git_version += [0] * (3 - len(git_version)) |
| 245 | + return tuple(git_version) |
| 246 | + |
| 247 | +def git_init(cwd): |
| 248 | + git_version = determine_git_version() |
| 249 | + if git_version is None: |
243 | 250 | print("\nGit can't be found! Can't initialize git for the project.\n") |
244 | 251 | return |
245 | | - git_version_str = str(git_version_out.stdout[12:], sys.stdout.encoding) |
246 | | - git_version = LooseVersion(git_version_str.rstrip()) |
247 | | - if LooseVersion("2.28.0") <= git_version: |
| 252 | + branch = "" |
| 253 | + if (2, 28, 0) <= git_version: |
248 | 254 | branch = " -b master" |
249 | 255 | subprocess.run(f"git init{branch}", shell=True, check=True, cwd=cwd) |
250 | 256 | print(""" |
|
0 commit comments