-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit.py
65 lines (39 loc) · 1.32 KB
/
git.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
# Copyright (c) 2021 Alethea Katherine Flowers.
# Published under the standard MIT License.
# Full text available at: https://opensource.org/licenses/MIT
import os
import tempfile
from wintertools.subprocess import run
def editor():
return run("git", "config", "--get", "core.editor").strip().split(" ")
def open_editor(content):
editor_ = editor()
handle, filename = tempfile.mkstemp(".md")
os.close(handle)
with open(filename, "w") as fh:
fh.write(content)
try:
run(*(editor_ + [filename]))
with open(filename, "r") as fh:
return fh.read()
finally:
os.remove(filename)
def root():
return run("git", "rev-parse", "--show-toplevel").strip()
def repo_name(remote="origin"):
origin = run("git", "config", "--get", f"remote.{remote}.url")
return origin.split(":")[1].rsplit(".")[0]
def fetch_tags():
run("git", "fetch", "--tags")
def tags():
return run("git", "tag", "--list", "--sort=-creatordate").split("\n")
def latest_tag():
return tags()[0]
def get_change_summary(start, end):
changes = run("git", "log", "--format=%s", f"{start}..{end}").split("\n")
list(filter(None, changes))
return changes
def tag(name, push=True):
run("git", "tag", name, capture=False)
if push:
run("git", "push", "origin", name)