3 # Copyright (c) 2010 Nazri Ramliy
6 test_description
='test "git log --decorate" colors'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 test_expect_success setup
'
15 git config diff.color.commit yellow &&
16 git config color.decorate.branch green &&
17 git config color.decorate.remoteBranch red &&
18 git config color.decorate.tag "reverse bold yellow" &&
19 git config color.decorate.stash magenta &&
20 git config color.decorate.grafted black &&
21 git config color.decorate.HEAD cyan &&
25 c_commit="<YELLOW>" &&
27 c_remoteBranch="<RED>" &&
28 c_tag="<BOLD;REVERSE;YELLOW>" &&
29 c_stash="<MAGENTA>" &&
31 c_grafted="<BLACK>" &&
40 git remote add -f other ./other &&
44 git stash save Changes to A.t
47 cmp_filtered_decorations
() {
48 sed "s/$OID_REGEX/COMMIT_ID/" actual | test_decode_color
>filtered
&&
49 test_cmp expect filtered
52 # We want log to show all, but the second parent to refs/stash is irrelevant
53 # to this test since it does not contain any decoration, hence --first-parent
54 test_expect_success
'commit decorations colored correctly' '
56 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
57 ${c_reset}${c_branch}main${c_reset}${c_commit}, \
58 ${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \
59 ${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B
60 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit}, \
61 ${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1
62 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset} \
63 On main: Changes to A.t
64 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
67 git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual &&
68 cmp_filtered_decorations
71 test_expect_success
'test coloring with replace-objects' '
72 test_when_finished rm -rf .git/refs/replace* &&
76 git replace HEAD~1 HEAD~2 &&
79 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
80 ${c_reset}${c_branch}main${c_reset}${c_commit}, \
81 ${c_reset}${c_tag}tag: D${c_reset}${c_commit})${c_reset} D
82 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: C${c_reset}${c_commit}, \
83 ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} B
84 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
87 git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual &&
88 cmp_filtered_decorations &&
89 git replace -d HEAD~1 &&
91 GIT_REPLACE_REF_BASE=refs/replace2/ git replace HEAD~1 HEAD~2 &&
92 GIT_REPLACE_REF_BASE=refs/replace2/ git log --first-parent \
93 --no-abbrev --decorate --oneline --color=always HEAD >actual &&
94 cmp_filtered_decorations
97 test_expect_success
'test coloring with grafted commit' '
98 test_when_finished rm -rf .git/refs/replace* &&
100 git replace --graft HEAD HEAD~2 &&
102 cat >expect <<-EOF &&
103 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
104 ${c_reset}${c_branch}main${c_reset}${c_commit}, \
105 ${c_reset}${c_tag}tag: D${c_reset}${c_commit}, \
106 ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D
107 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \
108 ${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B
109 ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
112 git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual &&
113 cmp_filtered_decorations &&
114 git replace -d HEAD &&
116 GIT_REPLACE_REF_BASE=refs/replace2/ git replace --graft HEAD HEAD~2 &&
117 GIT_REPLACE_REF_BASE=refs/replace2/ git log --first-parent \
118 --no-abbrev --decorate --oneline --color=always HEAD >actual &&
119 cmp_filtered_decorations