From 7d17eef31b434af9e4b275d9d18a2c0c261e6e07 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Thu, 10 Jan 2013 17:49:03 +0000 Subject: Don't fetch unnecessarily --- diff --git a/devbot/git.py b/devbot/git.py index adfeb33..c5bdd44 100644 --- a/devbot/git.py +++ b/devbot/git.py @@ -53,12 +53,19 @@ class Module: os.chdir(self.local) + if revision is None: + if self.tag and self._head_has_tag(self.tag): + return + + revision = self.tag + + if revision == self._get_commit_id(): + return + command.run(["git", "fetch"], retry=self._retry) if revision: command.run(["git", "checkout", revision]) - elif self.tag: - command.run(["git", "checkout", self.tag]) else: command.run(["git", "merge", "--ff-only", "origin/%s" % self._branch]) @@ -77,10 +84,6 @@ class Module: return subprocess.check_output(["git", "describe"]).strip() @_chdir - def get_commit_id(self): - return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip() - - @_chdir def get_annotation(self, tag): # FIXME this is fragile, there must be a better way @@ -111,6 +114,13 @@ class Module: return True + def _get_commit_id(self): + return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip() + + def _head_has_tag(self, tag): + tags = subprocess.check_output(["git", "tag", "--points-at", "HEAD"]) + return tag in tags.split("\n") + def get_module(module): return Module(path=config.get_source_dir(), -- cgit v0.9.1