summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-10-30 10:54:51 +0100
committerPeter Wu <peter@lekensteyn.nl>2015-10-30 10:54:51 +0100
commita83e5ab8eefacd69d255ecb35cf7b497aa3cae6d (patch)
tree5be83cd6de243d37877520f40aa9e92ec0eef525
parent97a39008b063b116e12688cc8615ce9a9a9ae195 (diff)
downloadscripts-a83e5ab8eefacd69d255ecb35cf7b497aa3cae6d.tar.gz
git-gerrit-diff: default to --color
-rwxr-xr-xgit-gerrit-diff20
1 files changed, 15 insertions, 5 deletions
diff --git a/git-gerrit-diff b/git-gerrit-diff
index 29d9ca0..0276faf 100755
--- a/git-gerrit-diff
+++ b/git-gerrit-diff
@@ -28,8 +28,11 @@ Examples:
git gerrit-diff origin/master-2.0 bug/12345
# Add options to git-log
- git gerrit-diff origin/master-2.0 --color --stat
- git gerrit-diff origin/master-2.0 bug/12345 --color
+ git gerrit-diff origin/master-2.0 --stat
+
+ # Do not pipe the output in a "less" pipe. Normally "less" is executed when
+ # the output is a tty and "--color" is added to the git-log options.
+ git gerrit-diff --no-pager origin/master-2.0
"""
import re, os, subprocess, sys
@@ -37,9 +40,10 @@ from collections import OrderedDict
def print_usage():
print("""
-Usage: git gerrit-diff [-h] [upstream [head]] [git log options]
+Usage: git gerrit-diff <options> [<upstream> [<head>]] [<git log options>]
- --no-pager Disable the less pager
+ --no-pager disable the less pager
+ --no-color omit --color option from git-log
-h, --help show this help
-v, --verbose be verbose
@@ -51,6 +55,7 @@ Usage: git gerrit-diff [-h] [upstream [head]] [git log options]
def parse_arguments():
no_pager = False
+ no_color = False
upstream = None
head = "HEAD"
git_options = []
@@ -63,6 +68,8 @@ def parse_arguments():
print_usage()
elif arg == "--no-pager":
no_pager = True
+ elif arg == "--no-color":
+ no_color = True
else:
break
count += 1
@@ -85,8 +92,11 @@ def parse_arguments():
# Ignore upstream and head
del args[:count]
+ # Always enable colors when the output is a TTY unless overridden.
+ if not no_color and os.isatty(sys.stdout.fileno()):
+ git_options.append("--color")
# remaining arguments are for git
- git_options = args
+ git_options += args
return no_pager, upstream, head, git_options