blob: 764039ddb0314ebadf583955840d3a926fccaae6 [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Søren Gjesse1c115b52019-08-14 12:43:57 +02002# Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6import utils
7import subprocess
8
Søren Gjesse1c115b52019-08-14 12:43:57 +02009
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020010def GitClone(url, checkout_dir):
11 cmd = ['git', 'clone', url, checkout_dir]
Søren Gjessee90156b2022-08-29 15:46:38 +020012 utils.PrintCmd(cmd)
13 return subprocess.check_call(cmd)
14
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020015
16def GitCheckout(revision, checkout_dir):
17 with utils.ChangedWorkingDirectory(checkout_dir):
18 cmd = ['git', 'checkout', revision]
19 utils.PrintCmd(cmd)
20 return subprocess.check_call(cmd)
21
22
Rico Wind1b52acf2021-03-21 12:36:55 +010023def GetHeadRevision(checkout_dir, use_main=False):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020024 revision_from = 'origin/main' if use_main else 'HEAD'
25 cmd = ['git', 'rev-parse', revision_from]
26 utils.PrintCmd(cmd)
27 with utils.ChangedWorkingDirectory(checkout_dir):
28 return subprocess.check_output(cmd).strip().decode('utf-8')