Commit bb050f61 authored by rmistry@google.com's avatar rmistry@google.com

Make checkout.GitCheckout usable from apply_issue

BUG=chromium:303433

Review URL: https://chromiumcodereview.appspot.com/25853003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@226774 0039d316-1c4b-4281-b951-d872f2087c98
parent 11145db6
...@@ -144,7 +144,7 @@ def main(): ...@@ -144,7 +144,7 @@ def main():
if scm_type == 'svn': if scm_type == 'svn':
scm_obj = checkout.SvnCheckout(full_dir, None, None, None, None) scm_obj = checkout.SvnCheckout(full_dir, None, None, None, None)
elif scm_type == 'git': elif scm_type == 'git':
scm_obj = checkout.GitCheckout(full_dir, None, None) scm_obj = checkout.GitCheckout(full_dir, None, None, None, None)
elif scm_type == None: elif scm_type == None:
scm_obj = checkout.RawCheckout(full_dir, None, None) scm_obj = checkout.RawCheckout(full_dir, None, None)
else: else:
......
...@@ -554,8 +554,6 @@ class GitCheckout(CheckoutBase): ...@@ -554,8 +554,6 @@ class GitCheckout(CheckoutBase):
"""Manages a git checkout.""" """Manages a git checkout."""
def __init__(self, root_dir, project_name, remote_branch, git_url, def __init__(self, root_dir, project_name, remote_branch, git_url,
commit_user, post_processors=None): commit_user, post_processors=None):
assert git_url
assert commit_user
super(GitCheckout, self).__init__(root_dir, project_name, post_processors) super(GitCheckout, self).__init__(root_dir, project_name, post_processors)
self.git_url = git_url self.git_url = git_url
self.commit_user = commit_user self.commit_user = commit_user
...@@ -565,6 +563,8 @@ class GitCheckout(CheckoutBase): ...@@ -565,6 +563,8 @@ class GitCheckout(CheckoutBase):
self.working_branch = 'working_branch' self.working_branch = 'working_branch'
# There is no reason to not hardcode origin. # There is no reason to not hardcode origin.
self.remote = 'origin' self.remote = 'origin'
# There is no reason to not hardcode master.
self.master_branch = 'master'
def prepare(self, revision): def prepare(self, revision):
"""Resets the git repository in a clean state. """Resets the git repository in a clean state.
...@@ -572,6 +572,7 @@ class GitCheckout(CheckoutBase): ...@@ -572,6 +572,7 @@ class GitCheckout(CheckoutBase):
Checks it out if not present and deletes the working branch. Checks it out if not present and deletes the working branch.
""" """
assert self.remote_branch assert self.remote_branch
assert self.git_url
if not os.path.isdir(self.project_path): if not os.path.isdir(self.project_path):
# Clone the repo if the directory is not present. # Clone the repo if the directory is not present.
...@@ -599,8 +600,9 @@ class GitCheckout(CheckoutBase): ...@@ -599,8 +600,9 @@ class GitCheckout(CheckoutBase):
self._check_call_git(['checkout', '--force', '--quiet', revision]) self._check_call_git(['checkout', '--force', '--quiet', revision])
else: else:
branches, active = self._branches() branches, active = self._branches()
if active != 'master': if active != self.master_branch:
self._check_call_git(['checkout', '--force', '--quiet', 'master']) self._check_call_git(
['checkout', '--force', '--quiet', self.master_branch])
self._sync_remote_branch() self._sync_remote_branch()
if self.working_branch in branches: if self.working_branch in branches:
...@@ -709,13 +711,15 @@ class GitCheckout(CheckoutBase): ...@@ -709,13 +711,15 @@ class GitCheckout(CheckoutBase):
cmd.append('--verbose') cmd.append('--verbose')
self._check_call_git(cmd) self._check_call_git(cmd)
found_files = self._check_output_git( found_files = self._check_output_git(
['diff', '%s/%s' % (self.remote, self.remote_branch), ['diff', '%s/%s' % (self.remote,
self.remote_branch or self.master_branch),
'--name-only']).splitlines(False) '--name-only']).splitlines(False)
assert sorted(patches.filenames) == sorted(found_files), ( assert sorted(patches.filenames) == sorted(found_files), (
sorted(patches.filenames), sorted(found_files)) sorted(patches.filenames), sorted(found_files))
def commit(self, commit_message, user): def commit(self, commit_message, user):
"""Commits, updates the commit message and pushes.""" """Commits, updates the commit message and pushes."""
assert self.commit_user
assert isinstance(commit_message, unicode) assert isinstance(commit_message, unicode)
current_branch = self._check_output_git( current_branch = self._check_output_git(
['rev-parse', '--abbrev-ref', 'HEAD']).strip() ['rev-parse', '--abbrev-ref', 'HEAD']).strip()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment