cros_merge_to_branch: filter out escape sequences
The git output will often include Esc[K sequences in order to rewrite
the current line. Filter those out when showing URLs to the user.
BUG=None
TEST=`cros_merge_to_branch 42703 R25` didn't include an escape sequence
Change-Id: I9df08a0ca3ca24dd75664968c58d6605e914e340
Reviewed-on: https://gerrit.chromium.org/gerrit/43649
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_merge_to_branch.py b/scripts/cros_merge_to_branch.py
index 4ecc120..7c7e3be 100644
--- a/scripts/cros_merge_to_branch.py
+++ b/scripts/cros_merge_to_branch.py
@@ -85,6 +85,8 @@
draft: If True, upload to refs/draft/|branch| rather than refs/for/|branch|.
dryrun: Don't actually upload a change but go through all the steps up to
and including git push --dry-run.
+ Returns:
+ A list of all the gerrit URLs found.
"""
upload_type = 'drafts' if draft else 'for'
# Download & setup the patch if need be.
@@ -228,10 +230,13 @@
# Now that we have the project checked out, let's apply our change and
# create a new change on Gerrit.
logging.info('Uploading change %s to branch %s', change, branch)
- url = _UploadChangeToBranch(work_dir, patch, branch, options.draft,
- options.dryrun)
+ urls = _UploadChangeToBranch(work_dir, patch, branch, options.draft,
+ options.dryrun)
logging.info('Successfully uploaded %s to %s', change, branch)
- if url:
+ for url in urls:
+ if url.endswith('\x1b[K'):
+ # Git will often times emit these escape sequences.
+ url = url[0:-3]
logging.info(' URL: %s', url)
except (cros_build_lib.RunCommandError, cros_patch.ApplyPatchException,