From d4fffee1c536c00d60cbfb99e5f50472db912cd3 Mon Sep 17 00:00:00 2001 From: "iannucci@chromium.org" Date: Fri, 28 Jun 2013 00:35:26 +0000 Subject: [PATCH] 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 --- gclient.py | 4 ++++ gclient_scm.py | 9 ++++++++- tests/gclient_scm_test.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index d6741fd14..1f4801b94 100755 --- a/gclient.py +++ b/gclient.py @@ -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 diff --git a/gclient_scm.py b/gclient_scm.py index 2cdee7df8..3e8f59c9b 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -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 diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 6cc7927d2..9d25d7bdd 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -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