From 59df9bd4d22715b03d1b765321021a59ebc9366b Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Thu, 29 Nov 2012 22:26:08 +0000 Subject: Git clean not out-of-source modules instead of removing --- diff --git a/devbot/build.py b/devbot/build.py index e958078..8740927 100644 --- a/devbot/build.py +++ b/devbot/build.py @@ -8,7 +8,6 @@ import time from devbot import command from devbot import config from devbot import environ -from devbot import git from devbot import state from devbot import utils @@ -78,7 +77,8 @@ def clean(): for module in config.load_modules(): if not module.out_of_source: - _rmtree(module.get_source_dir()) + if module.get_git_module().clean(): + print "Cleaned %s git repository." % module.name def _unlink_libtool_files(): def func(arg, dirname, fnames): @@ -91,9 +91,7 @@ def _pull_module(module): print "\n=== Pulling %s ===\n" % module.name try: - git_module = git.Module(config.get_source_dir(), module.name, - module.repo, module.tag) - git_module.update() + module.get_git_module().update() except subprocess.CalledProcessError: return False diff --git a/devbot/config.py b/devbot/config.py index 0f76644..cece353 100644 --- a/devbot/config.py +++ b/devbot/config.py @@ -7,6 +7,7 @@ import tempfile from devbot import distro from devbot import utils from devbot import plugins +from devbot import git devbot_dir = None config_dir = None @@ -54,6 +55,9 @@ class Module: return utils.get_commit_id(self.get_source_dir()) + def get_git_module(self): + return git.Module(get_source_dir(), self.name, self.repo, self.tag) + def _ensure_dir(dir): if not os.path.exists(dir): os.mkdir(dir) diff --git a/devbot/git.py b/devbot/git.py index 55fd9f5..8db61d2 100644 --- a/devbot/git.py +++ b/devbot/git.py @@ -36,3 +36,13 @@ class Module: command.run(["git", "checkout", self.tag]) else: command.run(["git", "merge", "origin", self._branch]) + + def clean(self): + try: + os.chdir(self.local) + except OSError: + return False + + command.run(["git", "clean", "-fdx"]) + + return True diff --git a/tests/devbot/test_git.py b/tests/devbot/test_git.py index 9468814..f5aca8e 100644 --- a/tests/devbot/test_git.py +++ b/tests/devbot/test_git.py @@ -102,5 +102,19 @@ class TestGit(unittest.TestCase): self.assertEquals("detachedchange", self._read_file(module)) + def test_clean(self): + module = self._setup_module() + module.update() + + to_clean_path = os.path.join(module.local, "changetoclean") + + f = open(to_clean_path, "w") + f.write("") + f.close() + + self.assertTrue(os.path.exists(to_clean_path)) + module.clean() + self.assertFalse(os.path.exists(to_clean_path)) + if __name__ == '__main__': unittest.main() -- cgit v0.9.1