Skip to content

Commit 5cc10c6

Browse files
authored
Merge pull request #8 from nmorey/dev/rpm
Color support
2 parents 88c1f07 + dab0e07 commit 5cc10c6

File tree

4 files changed

+99
-12
lines changed

4 files changed

+99
-12
lines changed

doc/git-sequencer-status.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ state in a human readable format.
2323

2424
This is largely inspired by the way Magit prints its status screen.
2525

26+
OPTIONS
27+
-------
28+
29+
--[no]-color::
30+
Force coloring to be on/off whether the command is run in a TTY or not
31+
32+
--help::
33+
Display usage
34+
2635
Authors
2736
-------
2837
'git-sequencer-status' is maintained by:

rpm/git-sequencer-status.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ License: GPL-3.0
2525
Group: Development/Tools/Version
2626
Url: https://github.com/nmorey/git-sequencer-status
2727
Source: %{name}-%{version}%{git_ver}.tar.bz2
28-
BuildRequires: git
28+
BuildRequires: git-core >= 2.0
2929
BuildRequires: bc
3030
BuildRequires: asciidoc
3131
BuildRequires: xmlto
32-
Requires: git
32+
Requires: git-core >= 2.0
3333
BuildArch: noarch
3434

3535
%description

sequencer-status

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,92 @@
22

33
export GIT_DIR=$(git rev-parse --git-dir)
44

5+
USE_COLOR=0
6+
if [ -t 1 ]; then
7+
USE_COLOR=1
8+
fi
9+
10+
usage()
11+
{
12+
local errCode=$1
13+
echo -e "Usage: $(basename $0) [OPTS]"
14+
echo -e "\t--[no-]color Force color to be enabled/disabled"
15+
echo -e "\t-h,--help Diplay usage"
16+
exit $errCode
17+
}
18+
19+
20+
while [ $# -gt 0 ]; do
21+
ARG=$1
22+
shift
23+
case "$ARG" in
24+
--color)
25+
USE_COLOR=1
26+
;;
27+
--no-color)
28+
USE_COLOR=0
29+
;;
30+
-h|--help)
31+
usage 0
32+
;;
33+
*)
34+
echo "ERROR: Invalid option $ARG" >&2
35+
usage 1
36+
;;
37+
esac
38+
done
39+
40+
if [ $USE_COLOR -eq 1 ]; then
41+
export YELLOW_NODIM='\033[00;33m'
42+
export RED_NODIM='\033[00;31m'
43+
export RED_DIM='\033[02;31m'
44+
export CYAN_BOLD='\033[01;36m'
45+
export WHITE='\033[00m'
46+
export COLOR_OPT="--color"
47+
else
48+
export COLOR_OPT="--no-color"
49+
fi
50+
51+
__git_log()
52+
{
53+
git --no-pager log $COLOR_OPT "$@"
54+
}
555
__colorize_todo()
656
{
7-
awk -vC0='\033[00;33m' -vC1='\033[00;31m' -vC2='\033[00m' '{printf( C0 "%-7s " C1 $2 " " C2, $1); for (i = 3; i <= NF; i++) { printf("%s ", $i);}; printf("\n");}'
57+
awk -vC0=$YELLOW_NODIM -vC1=$RED_NODIM -vC2=$WHITE \
58+
'{printf( C0 "%-7s " C1 $2 " " C2, $1); for (i = 3; i <= NF; i++) { printf("%s ", $i);}; printf("\n");}'
859
}
960

1061
__git_log_todo()
1162
{
12-
git --no-pager log --format='%C(yellow nodim)pick %C(red nodim)%h %C(white)%s' $*
63+
__git_log --format='%C(auto,yellow nodim)pick %C(auto,red nodim)%h %C(auto,white)%s' $*
1364
}
1465
__colorize_current()
1566
{
16-
awk -vC0='\033[01;36m' -vC1='\033[00;31m' -vC2='\033[00m' '{printf( C0 "%-7s " C1 $2 " " C2, $1); for (i = 3; i <= NF; i++) { printf("%s ", $i);}; printf("\n");}'
67+
awk -vC0=$CYAN_BOLD -vC1=$RED_NODIM -vC2=$WHITE \
68+
'{printf( C0 "%-7s " C1 $2 " " C2, $1); for (i = 3; i <= NF; i++) { printf("%s ", $i);}; printf("\n");}'
1769
}
1870
__git_log_current_unmerged()
1971
{
20-
git --no-pager log --format='%C(cyan bold)*pick %C(red nodim)%h %C(white)%s' $*
72+
__git_log --format='%C(auto,cyan bold)*pick %C(auto,red nodim)%h %C(auto,white)%s' $*
2173
}
2274
__git_log_current()
2375
{
24-
git --no-pager log --format='%C(cyan bold)pick %C(red nodim)%h %C(white)%s' $*
76+
__git_log --format='%C(auto,cyan bold)pick %C(auto,red nodim)%h %C(auto,white)%s' $*
2577
}
2678

2779
__colorize_done()
2880
{
29-
awk -vC0='\033[02;31m' -vC1='\033[00;31m' -vC2='\033[00m' '{printf( C0 "%-7s " C1 $2 " " C2, $1); for (i = 3; i <= NF; i++) { printf("%s ", $i);}; printf("\n");}'
81+
awk -vC0=$RED_DIM -vC1=$RED_NODIM -vC2=$WHITE '{printf( C0 "%-7s " C1 $2 " " C2, $1); for (i = 3; i <= NF; i++) { printf("%s ", $i);}; printf("\n");}'
3082
}
3183
__git_log_done()
3284
{
33-
git --no-pager log --format='%C(red dim)done %C(red nodim)%h %C(white)%s' $*
85+
__git_log --format='%C(auto,red dim)done %C(auto,red nodim)%h %C(auto,white)%s' $*
3486
}
3587

3688
__git_log_onto()
3789
{
38-
git --no-pager log -n 1 --format='%C(red dim)onto %C(red nodim)%h %C(white)%s' $*
90+
__git_log -n 1 --format='%C(auto,red dim)onto %C(auto,red nodim)%h %C(auto,white)%s' $*
3991

4092
}
4193
__has_unmerged()
@@ -101,7 +153,7 @@ __simple_action()
101153
local COMMIT=$(cat ${GIT_DIR}/$HEADFILE)
102154
shift 2
103155
echo "# " $* " a single commit"
104-
echo "*$ACTION $(git --no-pager log --format='%h %s' -n 1 $COMMIT)" | __colorize_current
156+
echo "*$ACTION $(__git_log --format='%h %s' -n 1 $COMMIT)" | __colorize_current
105157
__git_log_onto ${BASE}
106158
}
107159

travis/test.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export TMPDIR=$(mktemp -d)
1111
# Drop colors and SHA as they change from one run to another
1212
__sanitize_log()
1313
{
14-
sed -r -e "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" -e 's/^([a-zA-Z\*]* +)[a-f0-9]+ /\1 /g'
14+
sed -r -e 's/^([a-zA-Z\*]* +)[a-f0-9]+ /\1 /g'
1515
}
1616

1717
echo $TMPDIR
@@ -273,13 +273,39 @@ EOF
273273
git rebase --abort
274274
}
275275

276+
277+
test_color()
278+
{
279+
goto_repo
280+
echo "Checking coloring support"
281+
git checkout revert
282+
git rebase rebase_conflict > /dev/null 2>&1
283+
LOG=$($SEQDIR/sequencer-status --color | __sanitize_log)
284+
REF_LOG=$(cat <<EOF | __sanitize_log
285+
# Non-interactive rebase: revert onto rebase_conflict
286+
pick 38fb428 Fourth commit
287+
pick 46c2f5e Third commit
288+
*pick 22bc518 Second commit
289+
onto 68cb488 Alternate second
290+
EOF
291+
)
292+
293+
diff <(echo "$LOG") <(echo "$REF_LOG")
294+
if [ $? -eq 0 ]; then
295+
echo "Failure in color mode" >&2
296+
exit 1
297+
fi
298+
git rebase --abort
299+
}
300+
276301
juLog_fatal setup_repo
277302

278303
juLog test_cherry_pick
279304
juLog test_revert
280305
juLog test_rebase
281306
juLog test_am
282307
juLog test_rebase_interative
308+
juLog test_color
283309

284310

285311
# Post cleanup

0 commit comments

Comments
 (0)