|
1
|
|
|
# Copyright 2017 Starbot Discord Project |
|
2
|
|
|
# |
|
3
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
4
|
|
|
# you may not use this file except in compliance with the License. |
|
5
|
|
|
# You may obtain a copy of the License at |
|
6
|
|
|
# |
|
7
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
# |
|
9
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
10
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
11
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12
|
|
|
# See the License for the specific language governing permissions and |
|
13
|
|
|
# limitations under the License. |
|
14
|
|
|
'''Get current git branch and commit''' |
|
15
|
|
|
|
|
16
|
|
|
def git_commit(): |
|
17
|
|
|
'''Get the current git commit.''' |
|
18
|
|
|
if git_branch() == "UNKNOWN": |
|
19
|
|
|
return "UNKNOWN" |
|
20
|
|
|
else: |
|
21
|
|
|
with open(".git/refs/heads/{}".format(git_branch())) as file: |
|
22
|
|
|
commit = file.read() |
|
23
|
|
|
return commit.strip() |
|
24
|
|
|
|
|
25
|
|
|
def git_branch(): |
|
26
|
|
|
'''Get the current git branch.''' |
|
27
|
|
|
with open(".git/HEAD") as file: |
|
28
|
|
|
head_string = file.read() |
|
29
|
|
|
head_split = head_string.split(": ") |
|
30
|
|
|
if len(head_split) == 2: |
|
31
|
|
|
branch = head_split[1].split("/", 2)[-1] |
|
32
|
|
|
msg = branch.strip() |
|
33
|
|
|
else: |
|
34
|
|
|
msg = "UNKNOWN" |
|
35
|
|
|
return msg |
|
36
|
|
|
|
|
37
|
|
|
def get_remote(): |
|
38
|
|
|
with open(".git/config") as f: |
|
39
|
|
|
content = f.readlines() |
|
40
|
|
|
for line in content: |
|
41
|
|
|
if line.startswith('\turl'): |
|
42
|
|
|
return line.split("url = ")[1].strip() |
|
43
|
|
|
|
|
44
|
|
|
def get_url(): |
|
45
|
|
|
with open(".git/config") as f: |
|
46
|
|
|
content = f.readlines() |
|
47
|
|
|
for line in content: |
|
48
|
|
|
if line.startswith('\turl'): |
|
49
|
|
|
url = line.split("url = ")[1].strip()[:-4] |
|
50
|
|
|
slash = "/" |
|
51
|
|
|
return url + slash |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|