Chromium Code Reviews| Index: git_drover.py |
| diff --git a/git_drover.py b/git_drover.py |
| index ad6d0e13c745b7dc3e1e0c1983c52ac8339f84ef..f35eb217b674fb660bcaef8bbcd40b2e80ae685f 100755 |
| --- a/git_drover.py |
| +++ b/git_drover.py |
| @@ -265,8 +265,10 @@ class _Drover(object): |
| repo_status = self._run_git_command(['status', '--porcelain']).splitlines() |
| extra_files = [f[3:] for f in repo_status if f[:2] == ' D'] |
| if extra_files: |
| - self._run_git_command(['update-index', '--skip-worktree', '--'] + |
| - extra_files) |
| + extra_files_on_stdin = '\n'.join(extra_files) + '\n' |
| + self._run_git_command_with_stdin( |
| + ['update-index', '--skip-worktree', '--stdin'], |
| + stdin=extra_files_on_stdin) |
|
iannucci
2016/06/14 00:03:38
I would inline extra_files_on_stdin, but that's ju
scottmg
2016/06/14 00:13:16
Done.
|
| def _upload_and_land(self): |
| if self._dry_run: |
| @@ -314,6 +316,33 @@ class _Drover(object): |
| else: |
| raise Error('Command %r failed: %s' % (' '.join(args), e)) |
| + def _run_git_command_with_stdin(self, args, stdin): |
| + """Runs a git command with a provided stdin. |
| + |
| + Args: |
| + args: A list of strings containing the args to pass to git. |
| + stdin: A string to provide on stdin. |
| + |
| + Raises: |
| + Error: The command failed to complete successfully. |
| + """ |
| + cwd = self._workdir if self._workdir else self._parent_repo |
| + logging.debug('Running git %s (cwd %r)', ' '.join('%s' % arg |
| + for arg in args), cwd) |
| + |
| + # Discard stderr unless verbose is enabled. |
| + stderr = None if self._verbose else _DEV_NULL_FILE |
| + |
| + try: |
| + popen = subprocess.Popen(['git'] + args, shell=False, cwd=cwd, |
| + stderr=stderr, stdin=subprocess.PIPE) |
| + popen.communicate(stdin) |
| + popen.wait() |
|
iannucci
2016/06/14 00:03:38
communicate implies wait
scottmg
2016/06/14 00:13:16
Done.
|
| + if popen.returncode != 0: |
| + raise Error('Command %r failed' % ' '.join(args)) |
| + except OSError as e: |
| + raise Error('Command %r failed: %s' % (' '.join(args), e)) |
| + |
| def cherry_pick_change(branch, revision, parent_repo, dry_run, verbose=False): |
| """Cherry-picks a change into a branch. |