diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-11-29 21:38:10 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-11-29 21:38:10 (GMT) |
commit | 7df65ab65c28983f1792e1ac5f8326842b87ba2d (patch) | |
tree | 2133bf3a53d177866a05fe28569048b4e7dec0df /devbot | |
parent | 69982ce0d1b712ccfe5797fb83721ab856ec951b (diff) |
Add a devbot.git module with unit test
Diffstat (limited to 'devbot')
-rw-r--r-- | devbot/git.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/devbot/git.py b/devbot/git.py new file mode 100644 index 0000000..55fd9f5 --- /dev/null +++ b/devbot/git.py @@ -0,0 +1,38 @@ +import os + +from devbot import command + +class Module: + def __init__(self, path, name, remote, branch="master", tag=None): + self.remote = remote + self.local = os.path.join(path, name) + self.tag = tag + + self._path = path + self._name = name + self._branch = branch + + def _clone(self): + os.chdir(self._path) + + command.run(["git", "clone", "--progress", + self.remote, self._name], + retry=10) + + os.chdir(self.local) + + command.run(["git", "checkout", self._branch]) + + def update(self): + if not os.path.exists(os.path.join(self.local, ".git")): + self._clone() + return + + os.chdir(self.local) + + command.run(["git", "fetch"]) + + if self.tag: + command.run(["git", "checkout", self.tag]) + else: + command.run(["git", "merge", "origin", self._branch]) |