Skip to content

Commit 4df51d0

Browse files
authored
Rollup merge of #71559 - dillona:detect_git_progress_version, r=Mark-Simulacrum
Detect git version before attempting to use --progress Otherwise each update is run twice and errors are printed I've tested this with: git version 2.8.2.windows.1 (Windows) git version 2.26.2.266.ge870325ee8 (Linux built from source) git version 2.17.1 (Linux) git version 2.21.1 (Apple Git-122.3) (MacOS) I've tested with Python 2.7 (Windows, Linux, MacOS), 3.6 (Linux), and 3.7 (MacOS)
2 parents 4db65a1 + 7ac093f commit 4df51d0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/bootstrap/bootstrap.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import argparse
33
import contextlib
44
import datetime
5+
import distutils.version
56
import hashlib
67
import os
78
import re
@@ -331,6 +332,7 @@ def __init__(self):
331332
self.use_locked_deps = ''
332333
self.use_vendored_sources = ''
333334
self.verbose = False
335+
self.git_version = None
334336

335337
def download_stage0(self):
336338
"""Fetch the build system for Rust, written in Rust
@@ -743,15 +745,13 @@ def update_submodule(self, module, checked_out, recorded_submodules):
743745

744746
run(["git", "submodule", "-q", "sync", module],
745747
cwd=self.rust_root, verbose=self.verbose)
746-
try:
747-
run(["git", "submodule", "update",
748-
"--init", "--recursive", "--progress", module],
749-
cwd=self.rust_root, verbose=self.verbose, exception=True)
750-
except RuntimeError:
751-
# Some versions of git don't support --progress.
752-
run(["git", "submodule", "update",
753-
"--init", "--recursive", module],
754-
cwd=self.rust_root, verbose=self.verbose)
748+
749+
update_args = ["git", "submodule", "update", "--init", "--recursive"]
750+
if self.git_version >= distutils.version.LooseVersion("2.11.0"):
751+
update_args.append("--progress")
752+
update_args.append(module)
753+
run(update_args, cwd=self.rust_root, verbose=self.verbose, exception=True)
754+
755755
run(["git", "reset", "-q", "--hard"],
756756
cwd=module_path, verbose=self.verbose)
757757
run(["git", "clean", "-qdfx"],
@@ -763,9 +763,13 @@ def update_submodules(self):
763763
self.get_toml('submodules') == "false":
764764
return
765765

766-
# check the existence of 'git' command
766+
default_encoding = sys.getdefaultencoding()
767+
768+
# check the existence and version of 'git' command
767769
try:
768-
subprocess.check_output(['git', '--version'])
770+
git_version_output = subprocess.check_output(['git', '--version'])
771+
git_version_str = git_version_output.strip().split()[2].decode(default_encoding)
772+
self.git_version = distutils.version.LooseVersion(git_version_str)
769773
except (subprocess.CalledProcessError, OSError):
770774
print("error: `git` is not found, please make sure it's installed and in the path.")
771775
sys.exit(1)

0 commit comments

Comments
 (0)