From 63f1ab28b83ce8446e075c51b1390f7e6579fbba Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 22 Mar 2024 18:28:03 +0100 Subject: [PATCH] Show remote side colors when color is enabled When sending a patch for review, I get an uncolored message. The `SUCCESS` message comes from the remote side and the git client should wrap `SUCCESS` with color (see `color.remote` and `color.remote.` in `git-config`man page). The feature was added to C git in 2018 by Han-Wen Nienhuys who is working for Google and is one of Gerrit maintainers. The C git client would not enable colors when stdout is not a tty, which is the case since `run_command_status` captures the outputs in a pipe. Inject `--color.remote=always` when we have detected color can be used. The option is not shown in dry-run mode, I expect people to then copy-paste the command and it will then run interactively. Downstream bug: https://phabricator.wikimedia.org/T359981 Change-Id: I0aca9dc4b186500421a5f6d5e87cde825e091702 --- git_review/cmd.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index 0e935690..00de03e5 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -1868,10 +1868,14 @@ additional information: if options.no_thin: no_thin = '--no-thin' + color_remote = '' + if not options.dry and check_use_color_output(): + color_remote = '-c color.remote=always' + ref = "for" - cmd = ("git push --no-follow-tags %s %s HEAD:refs/%s/%s" % - (no_thin, remote, ref, branch)) + cmd = ("git %s push --no-follow-tags %s %s HEAD:refs/%s/%s" % + (color_remote, no_thin, remote, ref, branch)) push_options = [] if options.topic is not None: topic = options.topic