interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4207-log-decoration-colors.sh

134 lines · 4605 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2010 Nazri Ramliy
4#
5
6test_description='test "git log --decorate" colors'
7
8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11. ./test-lib.sh
12
13test_expect_success setup '
14 git config diff.color.commit yellow &&
15 git config color.decorate.branch green &&
16 git config color.decorate.remoteBranch red &&
17 git config color.decorate.tag "reverse bold yellow" &&
18 git config color.decorate.stash magenta &&
19 git config color.decorate.grafted black &&
20 git config color.decorate.HEAD cyan &&
21
22 c_reset="<RESET>" &&
23
24 c_commit="<YELLOW>" &&
25 c_branch="<GREEN>" &&
26 c_remoteBranch="<RED>" &&
27 c_tag="<BOLD;REVERSE;YELLOW>" &&
28 c_stash="<MAGENTA>" &&
29 c_HEAD="<CYAN>" &&
30 c_grafted="<BLACK>" &&
31
32 test_commit A &&
33 git clone . other &&
34 (
35 cd other &&
36 test_commit A1
37 ) &&
38
39 git remote add -f other ./other &&
40 test_commit B &&
41 git tag v1.0 &&
42 echo >>A.t &&
43 git stash save Changes to A.t
44'
45
46cmp_filtered_decorations () {
47 sed "s/$OID_REGEX/COMMIT_ID/" actual | test_decode_color >filtered &&
48 test_cmp expect filtered
49}
50
51# We want log to show all, but the second parent to refs/stash is irrelevant
52# to this test since it does not contain any decoration, hence --first-parent
53test_expect_success 'commit decorations colored correctly' '
54 cat >expect <<-EOF &&
55 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\
56${c_commit} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \
57${c_reset}${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \
58${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B
59${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
60${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_commit}, \
61${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit}, \
62${c_reset}${c_remoteBranch}other/HEAD${c_reset}${c_commit})${c_reset} A1
63 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
64${c_stash}refs/stash${c_reset}${c_commit})${c_reset} On main: Changes to A.t
65 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
66${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A
67 EOF
68
69 git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual &&
70 cmp_filtered_decorations
71'
72
73remove_replace_refs () {
74 git for-each-ref 'refs/replace*/**' --format='delete %(refname)' >in &&
75 git update-ref --stdin <in &&
76 rm in
77}
78
79test_expect_success 'test coloring with replace-objects' '
80 test_when_finished remove_replace_refs &&
81 test_commit C &&
82 test_commit D &&
83
84 git replace HEAD~1 HEAD~2 &&
85
86 cat >expect <<-EOF &&
87 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\
88${c_commit} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \
89${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit})${c_reset} D
90 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
91${c_tag}tag: ${c_reset}${c_tag}C${c_reset}${c_commit}, \
92${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} B
93 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
94${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A
95EOF
96
97 git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual &&
98 cmp_filtered_decorations &&
99 git replace -d HEAD~1 &&
100
101 GIT_REPLACE_REF_BASE=refs/replace2/ git replace HEAD~1 HEAD~2 &&
102 GIT_REPLACE_REF_BASE=refs/replace2/ git log --first-parent \
103 --no-abbrev --decorate --oneline --color=always HEAD >actual &&
104 cmp_filtered_decorations
105'
106
107test_expect_success 'test coloring with grafted commit' '
108 test_when_finished remove_replace_refs &&
109
110 git replace --graft HEAD HEAD~2 &&
111
112 cat >expect <<-EOF &&
113 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\
114${c_commit} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \
115${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit}, \
116${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D
117 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
118${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \
119${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B
120 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\
121${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A
122 EOF
123
124 git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual &&
125 cmp_filtered_decorations &&
126 git replace -d HEAD &&
127
128 GIT_REPLACE_REF_BASE=refs/replace2/ git replace --graft HEAD HEAD~2 &&
129 GIT_REPLACE_REF_BASE=refs/replace2/ git log --first-parent \
130 --no-abbrev --decorate --oneline --color=always HEAD >actual &&
131 cmp_filtered_decorations
132'
133
134test_done