|
33 | 33 | if __name__ == '__main__': |
34 | 34 |
|
35 | 35 | g2repo = git.Repo(path2repo) |
36 | | - if g2repo.active_branch.name != 'master': |
37 | | - print('Not on master branch') |
38 | | - sys.exit() |
| 36 | +# if g2repo.active_branch.name != 'master': |
| 37 | +# print('Not on master branch') |
| 38 | +# sys.exit() |
39 | 39 | if g2repo.head.is_detached: |
40 | | - print(f'Detached head {commit0[:6]!r}') |
| 40 | + print(f'Detached head {commit0[:7]!r}') |
41 | 41 | sys.exit() |
42 | 42 | # make a list of tags without a dash; get the largest numeric tag |
43 | 43 | # someday use the packaging module (but no more dependencies for now) |
44 | 44 | numtag = [i for i in g2repo.tags if '-' not in i.name] |
45 | 45 | max_numeric = max([int(i.name) for i in numtag if i.name.isdecimal()]) |
46 | 46 | # get the latest version number |
47 | | - releases = [i for i in g2repo.tags if '.' in i.name] |
48 | | - majors = [i.name.split('.')[0] for i in releases] |
| 47 | + releases = [i for i in g2repo.tags if '.' in i.name and i.name.startswith('v')] |
| 48 | + majors = [i.name.split('.')[0][1:] for i in releases] |
49 | 49 | major = max([int(i) for i in majors if i.isdecimal()]) |
50 | | - minors = [i.name.split('.')[1] for i in releases if i.name.startswith(f'{major}.')] |
| 50 | + minors = [i.name.split('.')[1] for i in releases if i.name.startswith(f'v{major}.')] |
51 | 51 | minor = max([int(i) for i in minors if i.isdecimal()]) |
52 | | - minis = [i.name.split('.',2)[2] for i in releases if i.name.startswith(f'{major}.{minor}')] |
| 52 | + minis = [i.name.split('.',2)[2] for i in releases if i.name.startswith(f'v{major}.{minor}')] |
53 | 53 | # mini can be integer, float or even have letters (5.2.1.1rc1) |
54 | 54 | # for now, ignore anything with letters or decimals |
55 | 55 | mini = max([int(i) for i in minis if i.isdecimal()]) |
56 | 56 | latest = f'{major}.{minor}.{mini}' |
57 | | - #nextmini = f'{major}.{minor}.{mini+1}' |
58 | | - nextminor = f'{major}.{minor+1}.0' |
| 57 | + #nextmini = f'v{major}.{minor}.{mini+1}' |
| 58 | + nextminor = f'v{major}.{minor+1}.0' |
59 | 59 | versiontag = nextminor |
60 | 60 | if versiontag in releases: |
61 | 61 | print(f'Versioning problem, generated next version {versiontag} already defined!') |
62 | 62 | versiontag = '?' |
63 | 63 |
|
64 | | - # scan for the newest untagged commits, stopping at the first |
65 | | - # tagged one |
66 | | - untagged = [] |
67 | | - for i,c in enumerate(g2repo.iter_commits('HEAD')): |
68 | | - if i > 500: |
69 | | - print('No tag found in 500 commits!') |
70 | | - #break |
71 | | - sys.exit() |
72 | | - tags = g2repo.git.tag('--points-at',c).split('\n') |
73 | | - if tags == ['']: |
74 | | - untagged.append(c) |
75 | | - else: |
76 | | - break |
77 | | - # add a tag to the newest untagged version |
78 | | - tagnum = max_numeric |
79 | | - for i in sorted(untagged,key=lambda k:k.committed_datetime,reverse=True): |
| 64 | + # is the newest commit tagged? |
| 65 | + c = g2repo.head.commit |
| 66 | + tags = g2repo.git.tag('--points-at',c).split('\n') |
| 67 | + if tags != ['']: |
| 68 | + print(f'Latest commit ({c.hexsha[:7]}) is already tagged ({tags}).') |
| 69 | + sys.exit() |
| 70 | + # add a tag to the newest commit |
| 71 | + tagnum = max_numeric + 1 |
| 72 | + while str(tagnum) in g2repo.tags: |
| 73 | + print(f'Error: {tagnum} would be repeated') |
80 | 74 | tagnum += 1 |
81 | | - if str(tagnum) in g2repo.tags: |
82 | | - print(f'Error: {tagnum} would be repeated') |
83 | | - break |
84 | | - g2repo.create_tag(str(tagnum),ref=i) |
85 | | - print(f'created tag {tagnum} for {i.hexsha[:7]}') |
86 | | - if versiontag != '?': |
87 | | - g2repo.create_tag(str(versiontag),ref=i) |
88 | | - print(f'created version # {versiontag} for {i.hexsha[:7]}') |
89 | | - break |
| 75 | + g2repo.create_tag(str(tagnum),ref=c) |
| 76 | + print(f'created tag {tagnum} for {c.hexsha[:7]}') |
| 77 | + if versiontag != '?': |
| 78 | + g2repo.create_tag(str(versiontag),ref=c) |
| 79 | + print(f'created version # {versiontag} for {c.hexsha[:7]}') |
90 | 80 |
|
91 | 81 | # create a file with GSAS-II version information |
92 | 82 | try: |
|
130 | 120 | fp.close() |
131 | 121 | print(f'Created git version file {pyfile} at {now} for {commit0[:7]!r}') |
132 | 122 |
|
133 | | - print('Now do\n\t git add \n\t git commit \n\t git push \n\t git push --follow-tags (better than git push --tags?)') |
| 123 | + print('Now do:\n\t git add \n\t git commit \n\t git push \n\t git push --tags (better than git push --follow-tags?)') |
134 | 124 |
|
135 | 125 | # Git 2.4 has added the push.followTags option to turn that flag on by default which you can set with: |
136 | 126 | # |
|
0 commit comments