You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.1 KiB

"""EasyEngine GIT module"""
10 years ago
from sh import git, ErrorReturnCode
from ee.core.logging import Log
import os
10 years ago
class EEGit:
"""Intialization of core variables"""
def ___init__():
# TODO method for core variables
pass
10 years ago
10 years ago
def add(self, paths, msg="Intializating"):
10 years ago
"""
Initializes Directory as repository if not already git repo.
and adds uncommited changes automatically
"""
10 years ago
for path in paths:
10 years ago
global git
git = git.bake("--git-dir={0}/.git".format(path),
"--work-tree={0}".format(path))
10 years ago
if os.path.isdir(path):
if not os.path.isdir(path+"/.git"):
try:
Log.debug(self, "EEGit: git init at {0}"
.format(path))
10 years ago
git.init(path)
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
10 years ago
Log.error(self, "Unable to git init at {0}"
.format(path))
10 years ago
status = git.status("-s")
if len(status.splitlines()) > 0:
try:
Log.debug(self, "EEGit: git commit at {0}"
.format(path))
10 years ago
git.add("--all")
git.commit("-am {0}".format(msg))
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
10 years ago
Log.error(self, "Unable to git commit at {0} "
.format(path))
10 years ago
else:
Log.debug(self, "EEGit: Path {0} not present".format(path))
def checkfilestatus(self, repo, filepath):
10 years ago
"""
Checks status of file, If its tracked or untracked.
"""
global git
git = git.bake("--git-dir={0}/.git".format(repo),
"--work-tree={0}".format(repo))
status = git.status("-s", "{0}".format(filepath))
if len(status.splitlines()) > 0:
return True
else:
return False