import os

from rtc2git import shouter


class Initializer:
    def __init__(self, config):
        self.repoName = config.gitRepoName
        self.clonedRepoName = config.clonedGitRepoName

    def createIgnore(self):
        newLine = "\n"
        with open(".gitignore", "w") as ignore:
            ignore.write(".jazz5" + newLine)
            ignore.write(".metadata" + newLine)

    def initalize(self):
        os.system("git init --bare " + self.repoName)
        shouter.shout("Repository was created in " + os.getcwd())
        os.system("git clone " + self.repoName)
        os.chdir(self.clonedRepoName)
        self.createIgnore()

    def initialCommitAndPush(self):
        shouter.shout("Initial git add")
        os.system("git add -A")
        shouter.shout("Finished initial git add")
        os.system("git commit -m \"Initial Commit\"")
        os.system("git push origin master")


class Commiter:
    def addAndcommit(self, changeEntry):
        os.system("git config --global --replace-all user.name \"" + changeEntry.author + "\"")
        os.system("git add -A")
        os.system("git commit -m \"" + changeEntry.comment + "\"")

    def branch(self, branchName):
        branchExist = os.system("git show-ref --verify --quiet refs/heads/" + branchName)
        if branchExist is 0:
            os.system("git checkout " + branchName)
        else:
            os.system("git checkout -b " + branchName)

    def pushBranch(self, branchName):
        os.system("git push origin " + branchName)

@@ -785,35 +785,52 @@
  initial git add
+, starting commit
 %22)%0A
-
         os.syste
@@ -863,24 +863,65 @@
  Commit%5C%22%22)%0A
+        shouter.shout(%22Finished commit%22)%0A
         os.s
@@ -952,16 +952,55 @@
 aster%22)%0A
+        shouter.shout(%22Finished push%22)%0A
 %0A%0Aclass 
@@ -1217,38 +1217,69 @@
 m %5C%22
-%22 + changeEntry.comment + %22%5C%22%22
+%25s%5C%22 --date %5C%22%25s%5C%22%22 %25 (changeEntry.comment, changeEntry.date)
 )%0A%0A 

add date to git commit