Commit d4fffee1 authored by iannucci@chromium.org's avatar iannucci@chromium.org

Add --upstream option to gclient to scrape git checkouts back to upstream state.

This will be used on the bots when calling apply_patch, which commits to git
repos.

R=dpranke@chromium.org,szager@chromium.org
BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@209040 0039d316-1c4b-4281-b951-d872f2087c98
parent e4d906fc
......@@ -1541,6 +1541,8 @@ def CMDsync(parser, args):
parser.add_option('-m', '--manually_grab_svn_rev', action='store_true',
help='Skip svn up whenever possible by requesting '
'actual HEAD revision from the repository')
parser.add_option('--upstream', action='store_true',
help='Make repo state match upstream branch.')
(options, args) = parser.parse_args(args)
client = GClient.LoadCurrentConfig(options)
......@@ -1590,6 +1592,8 @@ def CMDrevert(parser, args):
'references')
parser.add_option('-n', '--nohooks', action='store_true',
help='don\'t run hooks after the revert is complete')
parser.add_option('--upstream', action='store_true',
help='Make repo state match upstream branch.')
(options, args) = parser.parse_args(args)
# --force is implied.
options.force = True
......
......@@ -430,7 +430,10 @@ class GitWrapper(SCMWrapper):
# This is a big hammer, debatable if it should even be here...
if options.force or options.reset:
self._Run(['reset', '--hard', 'HEAD'], options)
target = 'HEAD'
if options.upstream and upstream_branch:
target = upstream_branch
self._Run(['reset', '--hard', target], options)
if current_type == 'detached':
# case 0
......@@ -578,6 +581,10 @@ class GitWrapper(SCMWrapper):
return self.update(options, [], file_list)
default_rev = "refs/heads/master"
if options.upstream:
if self._GetCurrentBranch():
upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
default_rev = upstream_branch or default_rev
_, deps_revision = gclient_utils.SplitUrlRevision(self.url)
if not deps_revision:
deps_revision = default_rev
......
......@@ -684,6 +684,7 @@ class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils,
self.force = False
self.reset = False
self.nohooks = False
self.upstream = False
self.merge = False
self.jobs = 1
self.delete_unversioned_trees = False
......
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