From a47f5afbfc84b53ea09a847cef14f02b87911bfe Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 12 Apr 2022 14:13:39 +1000 Subject: Enforce minimum git version Id4528209f1cd500afd06e2e61eb5689022251118 introduced a minimum git version. Abstract our existing check and setup a global with the local git version for tests. Add a minimum version check. Change-Id: I9d1de11269758a453ecc8dde0a4c631d8e762a91 --- git_review/cmd.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index b9879c5..61d30ef 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -44,6 +44,7 @@ USER_CONFIG = os.path.join(CONFIGDIR, "git-review.conf") DEFAULTS = dict(scheme='ssh', hostname=False, port=None, project=False, branch='master', remote="gerrit", rebase="1", track="0", usepushurl="0", notopic=False, branchauthor="name") +LOCAL_GIT_VERSION = (0, 0, 0) COPYRIGHT = """\ Copyright OpenStack Foundation and OpenDev Contributors @@ -62,6 +63,10 @@ See the License for the specific language governing permissions and limitations under the License. """ +# Bump this if a feature of a more recent git is unconditionally +# required +MINIMUM_GIT_VERSION = (2, 10, 0) + _branch_name = None _has_color = None @@ -219,6 +224,23 @@ def get_version(): return provider.version +def get_git_version(): + global LOCAL_GIT_VERSION + output = run_command("git version") + if "git version" in output: + try: + v = output.rsplit(None, 1)[1] + LOCAL_GIT_VERSION = tuple(map(int, v.split('.')[:3])) + except Exception: + printwrap("Could not determine git version!") + sys.exit(1) + if LOCAL_GIT_VERSION < MINIMUM_GIT_VERSION: + printwrap("Local git version %s < required git version %s" % + '.'.join(map(str, LOCAL_GIT_VERSION)), + '.'.join(map(str, MINIMUM_GIT_VERSION))) + sys.exit(1) + + def git_directories(): """Determine (absolute git work directory path, .git subdirectory path).""" cmd = ("git", "rev-parse", "--show-toplevel", "--git-dir") @@ -917,20 +939,9 @@ def rebase_changes(branch, remote, interactive=True): "re-run with the '-R' option enabled." % (branch, remote)) sys.exit(1) - # Determine git version to set rebase flags below. - output = run_command("git version") - rebase_flag = "--rebase-merges" - if "git version" in output: - try: - v = output.rsplit(None, 1)[1] - gitv = tuple(map(int, v.split('.')[:3])) - if gitv < (2, 18, 0): - rebase_flag = "--preserve-merges" - except Exception: - # We tried to determine the version and failed. Use current git - # flag as fallback. - warn("Could not determine git version. " - "Using modern git rebase flags.") + rebase_flag = '--rebase-merges' + if LOCAL_GIT_VERSION < (2, 18, 0): + rebase_flag = "--preserve-merges" interactive_flag = interactive and '-i' or '' @@ -1677,6 +1688,8 @@ additional information: branch = options.branch options.track = False + get_git_version() + global VERBOSE global UPDATE VERBOSE = options.verbose -- cgit v1.2.1