forked from rtcTo/rtc2git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitFunctions.py
99 lines (81 loc) · 3.29 KB
/
gitFunctions.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
import os
import shouter
import shell
class Initializer:
def __init__(self, config):
self.repoName = config.gitRepoName
self.clonedRepoName = config.clonedGitRepoName
self.author = config.user
@staticmethod
def createignore():
newline = "\n"
with open(".gitignore", "w") as ignore:
ignore.write(".jazz5" + newline)
ignore.write(".metadata" + newline)
ignore.write(".jazzShed" + newline)
def initalize(self):
shell.execute("git init --bare " + self.repoName)
shouter.shout("Repository was created in " + os.getcwd())
shell.execute("git clone " + self.repoName)
os.chdir(self.clonedRepoName)
shell.execute("git config push.default current")
self.createignore()
@staticmethod
def initialcommitandpush():
shouter.shout("Initial git add")
shell.execute("git add -A", os.devnull)
shouter.shout("Finished initial git add, starting commit")
shell.execute("git commit -m %s -q" % shell.quote("Initial Commit"))
shouter.shout("Finished commit")
shell.execute("git push origin master")
shouter.shout("Finished push")
class Commiter:
commitcounter = 0
@staticmethod
def addandcommit(changeentry):
Commiter.replaceauthor(changeentry.author, changeentry.email)
shell.execute("git add -A")
shell.execute(Commiter.getcommitcommand(changeentry))
Commiter.commitcounter += 1
if Commiter.commitcounter is 30:
shouter.shout("30 Commits happend, push current branch to avoid out of memory")
Commiter.pushbranch("")
Commiter.commitcounter = 0
shouter.shout("Commited change in local git repository")
@staticmethod
def getcommitcommand(changeentry):
comment = Commiter.replacegitcreatingfilesymbol(changeentry.comment)
return "git commit -m %s --date %s --author=%s" \
% (shell.quote(comment), shell.quote(changeentry.date), changeentry.getgitauthor())
@staticmethod
def replacegitcreatingfilesymbol(comment):
return Commiter.replacewords(" to ", comment, "-->", "->", ">")
@staticmethod
def replacewords(replacedwith, word, *replacingstrings):
for replacingstring in replacingstrings:
if replacingstring in word:
word = word.replace(replacingstring, replacedwith)
return word
@staticmethod
def replaceauthor(author, email):
shell.execute("git config --replace-all user.name " + shell.quote(author))
shell.execute("git config --replace-all user.email " + email)
@staticmethod
def branch(branchname):
branchexist = shell.execute("git show-ref --verify --quiet refs/heads/" + branchname)
if branchexist is 0:
Commiter.checkout(branchname)
else:
shell.execute("git checkout -b " + branchname)
@staticmethod
def pushbranch(branchname):
if branchname:
shouter.shout("Final push of branch " + branchname)
shell.execute("git push origin " + branchname)
@staticmethod
def checkout(branchname):
shell.execute("git checkout " + branchname)
class Differ:
@staticmethod
def has_diff():
return shell.execute("git diff --quiet") is 1