From 18fa4542d8cf73a579130403228777849d086869 Mon Sep 17 00:00:00 2001 From: "bratell@opera.com" Date: Tue, 21 May 2013 13:30:46 +0000 Subject: [PATCH] Don't "hang" gclient if fast-forward is not possible. As noticed in the TODO, raw_input (used by ask_for_data) works badly on background threads. On my Windows it doesn't even print the prompt which makes it hard to interact with it. Better to just abort and tell the user of gclient how to proceed. BUG= Review URL: https://chromiumcodereview.appspot.com/15421005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@201295 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_scm.py | 13 ++++++++----- tests/gclient_scm_test.py | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index 18bc0e389..1c3eb7949 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -69,7 +69,11 @@ class GitDiffFilterer(DiffFiltererWrapper): return re.sub("[a|b]/" + self._current_file, self._replacement_file, line) -def ask_for_data(prompt): +def ask_for_data(prompt, options): + if options.jobs > 1: + raise gclient_utils.Error("Background task requires input. Rerun " + "gclient with --jobs=1 so that\n" + "interaction is possible.") try: return raw_input(prompt) except KeyboardInterrupt: @@ -454,17 +458,16 @@ class GitWrapper(SCMWrapper): merge_args.append('--ff-only') merge_args.append(upstream_branch) merge_output = scm.GIT.Capture(merge_args, cwd=self.checkout_path) - except subprocess2.CalledProcessError, e: + except subprocess2.CalledProcessError as e: if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): if not printed_path: print('\n_____ %s%s' % (self.relpath, rev_str)) printed_path = True while True: try: - # TODO(maruel): That can't work with --jobs. action = ask_for_data( 'Cannot fast-forward merge, attempt to rebase? ' - '(y)es / (q)uit / (s)kip : ') + '(y)es / (q)uit / (s)kip : ', options) except ValueError: raise gclient_utils.Error('Invalid Character') if re.match(r'yes|y', action, re.I): @@ -755,7 +758,7 @@ class GitWrapper(SCMWrapper): 'Cannot rebase because of unstaged changes.\n' '\'git reset --hard HEAD\' ?\n' 'WARNING: destroys any uncommitted work in your current branch!' - ' (y)es / (q)uit / (s)how : ') + ' (y)es / (q)uit / (s)how : ', options) if re.match(r'yes|y', rebase_action, re.I): self._Run(['reset', '--hard', 'HEAD'], options) # Should this be recursive? diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 3f1ff3b02..babd133fb 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -684,6 +684,7 @@ class BaseGitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, self.reset = False self.nohooks = False self.merge = False + self.jobs = 1 self.delete_unversioned_trees = False sample_git_import = """blob