OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 # TODO(ukai): is it ok for gerrit case? | 2055 # TODO(ukai): is it ok for gerrit case? |
2056 base_branch = args[0] | 2056 base_branch = args[0] |
2057 else: | 2057 else: |
2058 if cl.GetBranch() is None: | 2058 if cl.GetBranch() is None: |
2059 DieWithError('Can\'t upload from detached HEAD state. Get on a branch!') | 2059 DieWithError('Can\'t upload from detached HEAD state. Get on a branch!') |
2060 | 2060 |
2061 # Default to diffing against common ancestor of upstream branch | 2061 # Default to diffing against common ancestor of upstream branch |
2062 base_branch = cl.GetCommonAncestorWithUpstream() | 2062 base_branch = cl.GetCommonAncestorWithUpstream() |
2063 args = [base_branch, 'HEAD'] | 2063 args = [base_branch, 'HEAD'] |
2064 | 2064 |
| 2065 # Make sure authenticated to Rietveld before running expensive hooks. It is |
| 2066 # a fast, best efforts check. Rietveld still can reject the authentication |
| 2067 # during the actual upload. |
| 2068 if not settings.GetIsGerrit() and auth_config.use_oauth2: |
| 2069 authenticator = auth.get_authenticator_for_host( |
| 2070 cl.GetRietveldServer(), auth_config) |
| 2071 if not authenticator.has_cached_credentials(): |
| 2072 raise auth.LoginRequiredError(cl.GetRietveldServer()) |
| 2073 |
2065 # Apply watchlists on upload. | 2074 # Apply watchlists on upload. |
2066 change = cl.GetChange(base_branch, None) | 2075 change = cl.GetChange(base_branch, None) |
2067 watchlist = watchlists.Watchlists(change.RepositoryRoot()) | 2076 watchlist = watchlists.Watchlists(change.RepositoryRoot()) |
2068 files = [f.LocalPath() for f in change.AffectedFiles()] | 2077 files = [f.LocalPath() for f in change.AffectedFiles()] |
2069 if not options.bypass_watchlists: | 2078 if not options.bypass_watchlists: |
2070 cl.SetWatchers(watchlist.GetWatchersForPaths(files)) | 2079 cl.SetWatchers(watchlist.GetWatchersForPaths(files)) |
2071 | 2080 |
2072 if not options.bypass_hooks: | 2081 if not options.bypass_hooks: |
2073 if options.reviewers or options.tbr_owners: | 2082 if options.reviewers or options.tbr_owners: |
2074 # Set the reviewer list now so that presubmit checks can access it. | 2083 # Set the reviewer list now so that presubmit checks can access it. |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3172 return 2 | 3181 return 2 |
3173 | 3182 |
3174 # Reload settings. | 3183 # Reload settings. |
3175 global settings | 3184 global settings |
3176 settings = Settings() | 3185 settings = Settings() |
3177 | 3186 |
3178 colorize_CMDstatus_doc() | 3187 colorize_CMDstatus_doc() |
3179 dispatcher = subcommand.CommandDispatcher(__name__) | 3188 dispatcher = subcommand.CommandDispatcher(__name__) |
3180 try: | 3189 try: |
3181 return dispatcher.execute(OptionParser(), argv) | 3190 return dispatcher.execute(OptionParser(), argv) |
| 3191 except auth.AuthenticationError as e: |
| 3192 DieWithError(str(e)) |
3182 except urllib2.HTTPError, e: | 3193 except urllib2.HTTPError, e: |
3183 if e.code != 500: | 3194 if e.code != 500: |
3184 raise | 3195 raise |
3185 DieWithError( | 3196 DieWithError( |
3186 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 3197 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
3187 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 3198 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
3188 return 0 | 3199 return 0 |
3189 | 3200 |
3190 | 3201 |
3191 if __name__ == '__main__': | 3202 if __name__ == '__main__': |
3192 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3203 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3193 # unit testing. | 3204 # unit testing. |
3194 fix_encoding.fix_encoding() | 3205 fix_encoding.fix_encoding() |
3195 colorama.init() | 3206 colorama.init() |
3196 try: | 3207 try: |
3197 sys.exit(main(sys.argv[1:])) | 3208 sys.exit(main(sys.argv[1:])) |
3198 except KeyboardInterrupt: | 3209 except KeyboardInterrupt: |
3199 sys.stderr.write('interrupted\n') | 3210 sys.stderr.write('interrupted\n') |
3200 sys.exit(1) | 3211 sys.exit(1) |
OLD | NEW |