-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlasttag.py
executable file
·99 lines (70 loc) · 1.91 KB
/
lasttag.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/python
import os
import sys
import git
import asyncio
import argparse
from glob import glob
def arg_init() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s [path to repo] [OPTION]...",
description="Print last git tag"
)
parser.add_argument(
"dest",
nargs='*',
default=os.getcwd(),
help='Path to repo'
)
parser.add_argument(
"-f", "--fetch",
action='store_true',
help="If flag set lasttag will fetch from origin first"
)
parser.add_argument(
"-p", "--pull",
action='store_true',
help="If flag set lasttag will only pull from origin"
)
parser.add_argument(
"-r", "--recursive",
action='store_true',
help="if flag is set it will do action recursively in all subfolders where applicable"
)
parser.parse_args(['--fetch'])
return parser
def pull(repo_origin):
print(f'Pulling ${repo_origin}')
repo_origin.pull()
def get_subfolders(path):
return glob(f'{path}/*/')
def set_origin(path):
repo = git.Repo(path)
origin = repo.remotes.origin
return origin
def get_tag(path):
try:
repo = git.Repo(path)
except git.exc.InvalidGitRepositoryError as e:
print(f'this is not repo path ${path}')
tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
latest_tag = tags[-1]
print(latest_tag)
def main():
parser = arg_init()
args = parser.parse_args()
if args.fetch:
set_origin(args.dest).fetch()
if args.pull:
pull(set_origin(args.dest))
if args.recursive:
for sub in get_subfolders(args.dest):
os.chdir(sub)
print(f'Pulling ${sub}')
pull(set_origin(sub))
get_tag(sub)
print("all paths pulled")
quit()
get_tag(args.dest)
if __name__ == '__main__':
main()