-
Notifications
You must be signed in to change notification settings - Fork 20
/
write-ref
executable file
·66 lines (57 loc) · 2.25 KB
/
write-ref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#
# Directly set a given ref to a commit, erroring if it doesn't
# exist and --create is not specified. You might use this
# to implement something like immutable tags.
#
# Copyright 2016 Colin Walters <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('OSTree', '1.0')
from gi.repository import GLib, Gio, OSTree
import argparse
import sys
staging_key = 'redhat.staging'
def fatal(msg):
print >>sys.stderr, msg
sys.exit(1)
parser = argparse.ArgumentParser(prog="ostree-edit-detached")
parser.add_argument("--repo", help="Repo path",
action='store', required=True)
parser.add_argument("--create", help="Branch",
action='store_true')
parser.add_argument("--ref", help="Branch",
action='store', required=True)
parser.add_argument("--commit", help="commit",
action='store', required=True)
args = parser.parse_args()
r = OSTree.Repo.new(Gio.File.new_for_path(args.repo))
r.open(None)
[_, current] = r.resolve_rev(args.ref, True)
if current is None:
print("Ref {} does not currently exist".format(args.ref))
if not args.create:
print("--create not specified, exiting")
sys.exit(1)
else:
print("Previously, {} = {}".format(args.ref, current))
if args.create:
print("--create specified but ref already exists!")
sys.exit(1)
[_,commit,commitstate] = r.load_commit(args.commit)
if commitstate != 0:
print("Invalid commit state for {}: {}".format(args.commit, commitstate))
r.set_ref_immediate(None, args.ref, args.commit)
print("Set {} => {}".format(args.ref, args.commit))