forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.py
More file actions
42 lines (28 loc) · 1017 Bytes
/
git.py
File metadata and controls
42 lines (28 loc) · 1017 Bytes
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
import os
from tempfile import NamedTemporaryFile
from commitizen import cmd
def tag(tag: str):
c = cmd.run(f"git tag {tag}")
return c
def commit(message: str, args=""):
f = NamedTemporaryFile("wb", delete=False)
f.write(message.encode("utf-8"))
f.close()
c = cmd.run(f"git commit {args} -F {f.name}")
os.unlink(f.name)
return c
def get_commits(start: str, end: str = "HEAD", from_beginning: bool = False) -> list:
c = cmd.run(f"git log --pretty=format:%s%n%b {start}...{end}")
if from_beginning:
c = cmd.run(f"git log --pretty=format:%s%n%b {end}")
if not c.out:
return []
return c.out.split("\n")
def tag_exist(tag: str) -> bool:
c = cmd.run(f"git tag --list {tag}")
return tag in c.out
def is_staging_clean() -> bool:
"""Check if staing is clean"""
c = cmd.run("git diff --no-ext-diff --name-only")
c_cached = cmd.run("git diff --no-ext-diff --cached --name-only")
return not (bool(c.out) or bool(c_cached.out))