-
Notifications
You must be signed in to change notification settings - Fork 0
/
is-tagged.py
57 lines (50 loc) · 1.59 KB
/
is-tagged.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Checks if the current revision of the repository is a tagged revision,
but not 'tip'.
usage:
python is-tagged.py [/path/to/repo]
if no path is given, the current working directory will be used.
Exit status:
0 if the current revision is a tagged version OR
if the current revision was used for signing/tagging OR
if path is not a Mercurial repository OR
if module import should fail for some reason
1 if the current revision has no tag, except 'tip'
"""
import re
import sys
try:
from mercurial import hg, ui
except ImportError: # no Mercurial at all
sys.exit(0)
try:
from mercurial.error import Abort, RepoError
except ImportError:
try:
from mercurial.repo import RepoError
from mercurial.util import Abort
except ImportError: # something old/new?
sys.exit(0)
RE = r'^Added\s(?:signature|tag)\s(?:[\w\.]+\s)?for\schangeset\s[\da-f]{12,}$'
def main():
if len(sys.argv) > 1:
path = sys.argv[1].strip()
else:
path = '.'
try:
repo = hg.repository(ui.ui(), path)
except (Abort, RepoError): # no/bad repo? no extra version info
return 0
parents_id = repo.dirstate.parents()[0]
ctx = repo.changectx(parents_id)
if re.match(RE, ctx.description()): # tag or sig was added for a release
return 0
for tag, nodeid in repo.tags().iteritems():
if tag != 'tip' and parents_id == nodeid: # tagged
return 0
# not tagged
return 1
if __name__ == '__main__':
sys.exit(main())