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