diff options
author | Ravi Mistry <rmistry@google.com> | 2016-11-23 08:38:18 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-23 14:12:05 +0000 |
commit | badc137e3e9190787f2ad41001638d9db73b2eb1 (patch) | |
tree | 9a3714f55be38da48423997c8936b6bb2dd9c7bd /infra/bots/git_utils.py | |
parent | 59dc41175d99d0a31c046aec0c26c4d82a3a3574 (diff) |
Add Gerrit support to RecreateSKPs
Tested by modifying Canary builder to upload a CL: https://task-scheduler.skia.org/job/20161122T163246.824881948Z_00000000000039de
The above uploaded Gerrit CL: https://skia-review.googlesource.com/c/5140/
BUG=skia:5979
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4889
Change-Id: I5527c9d4219b879d5220136949704ea0fc556f85
Reviewed-on: https://skia-review.googlesource.com/4889
Commit-Queue: Ravi Mistry <rmistry@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
Diffstat (limited to 'infra/bots/git_utils.py')
-rw-r--r-- | infra/bots/git_utils.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/infra/bots/git_utils.py b/infra/bots/git_utils.py index 73768f6535..a5a93931d4 100644 --- a/infra/bots/git_utils.py +++ b/infra/bots/git_utils.py @@ -6,7 +6,11 @@ """This module contains functions for using git.""" import re +import shutil import subprocess +import tempfile + +import utils class GitLocalConfig(object): @@ -85,3 +89,45 @@ class GitBranch(object): subprocess.check_call(['git', 'checkout', 'master']) if self._delete_when_finished: subprocess.check_call(['git', 'branch', '-D', self._branch_name]) + + +class NewGitCheckout(utils.tmp_dir): + """Creates a new local checkout of a Git repository.""" + + def __init__(self, repository, commit='HEAD'): + """Set parameters for this local copy of a Git repository. + + Because this is a new checkout, rather than a reference to an existing + checkout on disk, it is safe to assume that the calling thread is the + only thread manipulating the checkout. + + You must use the 'with' statement to create this object: + + with NewGitCheckout(*args) as checkout: + # use checkout instance + # the checkout is automatically cleaned up here + + Args: + repository: URL of the remote repository (e.g., + 'https://skia.googlesource.com/common') or path to a local repository + (e.g., '/path/to/repo/.git') to check out a copy of + commit: commit hash, branch, or tag within refspec, indicating what point + to update the local checkout to + """ + super(NewGitCheckout, self).__init__() + self._repository = repository + self._commit = commit + + @property + def root(self): + """Returns the root directory containing the checked-out files.""" + return self.name + + def __enter__(self): + """Check out a new local copy of the repository. + + Uses the parameters that were passed into the constructor. + """ + super(NewGitCheckout, self).__enter__() + subprocess.check_output(args=['git', 'clone', self._repository, self.root]) + return self |