From b15c6f016d66c3e31c4ab7069bd43a9a1e310745 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 4 Feb 2015 14:19:49 +0000 Subject: [PATCH] Add the ability to tell if a commit is in a specific tree. --- wptrunner/update/sync.py | 3 ++- wptrunner/update/tree.py | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/wptrunner/update/sync.py b/wptrunner/update/sync.py index 2b443b406a030a..5231414abd238e 100644 --- a/wptrunner/update/sync.py +++ b/wptrunner/update/sync.py @@ -158,7 +158,8 @@ def create(self, state): local_tree.add_new(os.path.relpath(state.tests_path, local_tree.root)) updated = local_tree.update_patch(include=[state.tests_path, - state.metadata_path]) + state.metadata_path]) + local_tree.commit_patch() if not updated: self.logger.info("Nothing to sync") diff --git a/wptrunner/update/tree.py b/wptrunner/update/tree.py index 0c1c5c2a7fdd44..292a45a4fe245c 100644 --- a/wptrunner/update/tree.py +++ b/wptrunner/update/tree.py @@ -124,6 +124,13 @@ def update_patch(self, include=None): def commit_patch(self): self.hg("qfinish") + def contains_commit(self, commit): + try: + self.hg("identify", "-r", commit.sha1) + return True + except subprocess.CalledProcessError: + return False + class GitTree(object): name = "git" @@ -237,20 +244,24 @@ def update_patch(self, include=None): of filenames (which must already be in the repo) to commit """ - assert self.message is not None - if include is not None: args = tuple(include) else: args = () if self.git("status", "-uno", "-z", *args).strip(): - self.git("commit", "-m", self.message, *args) + self.git("add", *args) return True return False def commit_patch(self): - pass + assert self.message is not None + + if self.git("diff", "--name-only", "--staged", "-z").strip(): + self.git("commit", "-m", self.message) + return True + + return False def init(self): self.git("init") @@ -320,6 +331,13 @@ def submodules(self): rv.append(parts[1]) return rv + def contains_commit(self, commit): + try: + self.git("rev-parse", "--verify", commit.sha1) + return True + except subprocess.CalledProcessError: + return False + class CommitMessage(object): def __init__(self, text):