Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1030)

Unified Diff: py/utils/git_utils.py

Issue 484143002: git_utils.py: allow checkouts of local repositories at any commithash along master branch (Closed) Base URL: https://skia.googlesource.com/common.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | py/utils/git_utils_manualtest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: py/utils/git_utils.py
diff --git a/py/utils/git_utils.py b/py/utils/git_utils.py
index 52ad83a6409fd4ff17853e966ba69b68775cdc28..9abde2e1506b3773c47522fb9e279046ad745fbd 100644
--- a/py/utils/git_utils.py
+++ b/py/utils/git_utils.py
@@ -152,8 +152,8 @@ class GitBranch(object):
class NewGitCheckout(object):
"""Creates a new local checkout of a Git repository."""
- def __init__(self, repository, refspec=None, subdir=None,
- containing_dir=None):
+ def __init__(self, repository, branch='master', commithash='HEAD',
+ subdir=None, containing_dir=None):
"""Check out a new local copy of the repository.
Because this is a new checkout, rather than a reference to an existing
@@ -168,9 +168,12 @@ class NewGitCheckout(object):
# the checkout is automatically cleaned up here
Args:
- repository: name of the remote repository
- refspec: an arbitrary remote ref (e.g., the name of a branch);
- if None, allow the git command to pick a default
+ 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
+ branch: which branch to fetch from the repository
+ commithash: rewind the local checkout to a particular commithash (which
+ must be present along the branch specified above)
subdir: if specified, the caller only wants access to files within this
subdir in the repository.
For now, we check out the entire repository regardless of this param,
@@ -188,11 +191,13 @@ class NewGitCheckout(object):
else:
self._file_root = self._git_root
- pull_cmd = [GIT, 'pull', repository]
- if refspec:
- pull_cmd.append(refspec)
+ local_branch_name = 'local'
self._run_in_git_root(args=[GIT, 'init'])
- self._run_in_git_root(args=pull_cmd)
+ self._run_in_git_root(args=[GIT, 'fetch', repository, branch])
+ self._run_in_git_root(args=[GIT, 'merge', 'FETCH_HEAD'])
+ self._run_in_git_root(args=[GIT, 'branch', local_branch_name, commithash])
+ self._run_in_git_root(args=[GIT, 'checkout', local_branch_name])
borenet 2014/08/19 14:30:31 Why not just do: $ git clone <repository> $ git ch
epoger 2014/08/19 15:16:03 Seems to work (with some adjustments). I think th
borenet 2014/08/19 15:24:28 What repository are we checking out? I think Skia
epoger 2014/08/19 15:42:05 The primary use case is indeed the Skia repo. Per
borenet 2014/08/19 15:50:20 SGTM. You're welcome to change it back if you wan
+
@property
def root(self):
« no previous file with comments | « no previous file | py/utils/git_utils_manualtest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698