Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 2 | # 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 | |
| 6 | import utils |
| 7 | import subprocess |
| 8 | |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 9 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 10 | def GitClone(url, checkout_dir): |
| 11 | cmd = ['git', 'clone', url, checkout_dir] |
Søren Gjesse | e90156b | 2022-08-29 15:46:38 +0200 | [diff] [blame] | 12 | utils.PrintCmd(cmd) |
| 13 | return subprocess.check_call(cmd) |
| 14 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 15 | |
| 16 | def 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 Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 23 | def GetHeadRevision(checkout_dir, use_main=False): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 24 | 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') |