Skip to content

Commit

Permalink
Detect git version before attempting to use --progress
Browse files Browse the repository at this point in the history
Otherwise each update is run twice and errors are printed
  • Loading branch information
dillona committed Apr 25, 2020
1 parent 659951c commit 7ac093f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import contextlib
import datetime
import distutils.version
import hashlib
import os
import re
Expand Down Expand Up @@ -331,6 +332,7 @@ def __init__(self):
self.use_locked_deps = ''
self.use_vendored_sources = ''
self.verbose = False
self.git_version = None

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

run(["git", "submodule", "-q", "sync", module],
cwd=self.rust_root, verbose=self.verbose)
try:
run(["git", "submodule", "update",
"--init", "--recursive", "--progress", module],
cwd=self.rust_root, verbose=self.verbose, exception=True)
except RuntimeError:
# Some versions of git don't support --progress.
run(["git", "submodule", "update",
"--init", "--recursive", module],
cwd=self.rust_root, verbose=self.verbose)

update_args = ["git", "submodule", "update", "--init", "--recursive"]
if self.git_version >= distutils.version.LooseVersion("2.11.0"):
update_args.append("--progress")
update_args.append(module)
run(update_args, cwd=self.rust_root, verbose=self.verbose, exception=True)

run(["git", "reset", "-q", "--hard"],
cwd=module_path, verbose=self.verbose)
run(["git", "clean", "-qdfx"],
Expand All @@ -763,9 +763,13 @@ def update_submodules(self):
self.get_toml('submodules') == "false":
return

# check the existence of 'git' command
default_encoding = sys.getdefaultencoding()

# check the existence and version of 'git' command
try:
subprocess.check_output(['git', '--version'])
git_version_output = subprocess.check_output(['git', '--version'])
git_version_str = git_version_output.strip().split()[2].decode(default_encoding)
self.git_version = distutils.version.LooseVersion(git_version_str)
except (subprocess.CalledProcessError, OSError):
print("error: `git` is not found, please make sure it's installed and in the path.")
sys.exit(1)
Expand Down

0 comments on commit 7ac093f

Please sign in to comment.