Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t3202-show-branch.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t3202-show-branch.sh` 286 lines ยท 8501 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test show-branch' 4 5 . ./test-lib.sh 6 7 test_expect_success 'error descriptions on empty repository' ' 8 current=$(git branch --show-current) && 9 cat >expect <<-EOF && 10 error: no commit on branch '\''$current'\'' yet 11 EOF 12 test_must_fail git branch --edit-description 2>actual && 13 test_cmp expect actual && 14 test_must_fail git branch --edit-description $current 2>actual && 15 test_cmp expect actual 16 ' 17 18 test_expect_success 'fatal descriptions on empty repository' ' 19 current=$(git branch --show-current) && 20 cat >expect <<-EOF && 21 fatal: no commit on branch '\''$current'\'' yet 22 EOF 23 test_must_fail git branch --set-upstream-to=non-existent 2>actual && 24 test_cmp expect actual && 25 test_must_fail git branch -c new-branch 2>actual && 26 test_cmp expect actual 27 ' 28 29 test_expect_success 'setup' ' 30 test_commit initial && 31 for i in $(test_seq 1 10) 32 do 33 git checkout -b branch$i initial && 34 test_commit --no-tag branch$i || return 1 35 done && 36 git for-each-ref \ 37 --sort=version:refname \ 38 --format="%(refname:strip=2)" \ 39 "refs/heads/branch*" >branches.sorted && 40 sed "s/^> //" >expect <<-\EOF 41 > ! [branch1] branch1 42 > ! [branch2] branch2 43 > ! [branch3] branch3 44 > ! [branch4] branch4 45 > ! [branch5] branch5 46 > ! [branch6] branch6 47 > ! [branch7] branch7 48 > ! [branch8] branch8 49 > ! [branch9] branch9 50 > * [branch10] branch10 51 > ---------- 52 > * [branch10] branch10 53 > + [branch9] branch9 54 > + [branch8] branch8 55 > + [branch7] branch7 56 > + [branch6] branch6 57 > + [branch5] branch5 58 > + [branch4] branch4 59 > + [branch3] branch3 60 > + [branch2] branch2 61 > + [branch1] branch1 62 > +++++++++* [branch10^] initial 63 EOF 64 ' 65 66 test_expect_success 'show-branch with more than 8 branches' ' 67 git show-branch $(cat branches.sorted) >actual && 68 test_cmp expect actual 69 ' 70 71 test_expect_success 'show-branch with showbranch.default' ' 72 for branch in $(cat branches.sorted) 73 do 74 test_config showbranch.default $branch --add || return 1 75 done && 76 git show-branch >actual && 77 test_cmp expect actual 78 ' 79 80 test_expect_success 'show-branch --color output' ' 81 sed "s/^> //" >expect <<-\EOF && 82 > ! [branch1] branch1 83 > ! [branch2] branch2 84 > ! [branch3] branch3 85 > ! [branch4] branch4 86 > ! [branch5] branch5 87 > ! [branch6] branch6 88 > ! [branch7] branch7 89 > ! [branch8] branch8 90 > ! [branch9] branch9 91 > * [branch10] branch10 92 > ---------- 93 > * [branch10] branch10 94 > + [branch9] branch9 95 > + [branch8] branch8 96 > + [branch7] branch7 97 > + [branch6] branch6 98 > + [branch5] branch5 99 > + [branch4] branch4 100 > + [branch3] branch3 101 > + [branch2] branch2 102 > + [branch1] branch1 103 > +++++++++* [branch10^] initial 104 EOF 105 git show-branch --color=always $(cat branches.sorted) >actual.raw && 106 test_decode_color actual && 107 test_cmp expect actual 108 ' 109 110 test_expect_success 'show branch --remotes' ' 111 cat >expect.err <<-\EOF && 112 No revs to be shown. 113 EOF 114 git show-branch -r 2>actual.err >actual.out && 115 test_cmp expect.err actual.err && 116 test_must_be_empty actual.out 117 ' 118 119 test_expect_success 'show-branch --sparse' ' 120 test_when_finished "git checkout branch10 && git branch -D branchA" && 121 git checkout -b branchA branch10 && 122 git merge -s ours -m "merge 1 and 10 to make A" branch1 && 123 git commit --allow-empty -m "another" && 124 125 git show-branch --sparse >out && 126 test_grep "merge 1 and 10 to make A" out && 127 128 git show-branch >out && 129 test_grep ! "merge 1 and 10 to make A" out && 130 131 git show-branch --no-sparse >out && 132 test_grep ! "merge 1 and 10 to make A" out 133 ' 134 135 test_expect_success 'setup show branch --list' ' 136 sed "s/^> //" >expect <<-\EOF 137 > [branch1] branch1 138 > [branch2] branch2 139 > [branch3] branch3 140 > [branch4] branch4 141 > [branch5] branch5 142 > [branch6] branch6 143 > [branch7] branch7 144 > [branch8] branch8 145 > [branch9] branch9 146 > * [branch10] branch10 147 EOF 148 ' 149 150 test_expect_success 'show branch --list' ' 151 git show-branch --list $(cat branches.sorted) >actual && 152 test_cmp expect actual 153 ' 154 155 test_expect_success 'show branch --list has no --color output' ' 156 git show-branch --color=always --list $(cat branches.sorted) >actual && 157 test_cmp expect actual 158 ' 159 160 test_expect_success 'show branch --merge-base with one argument' ' 161 for branch in $(cat branches.sorted) 162 do 163 git rev-parse $branch >expect && 164 git show-branch --merge-base $branch >actual && 165 test_cmp expect actual || return 1 166 done 167 ' 168 169 test_expect_success 'show branch --merge-base with two arguments' ' 170 for branch in $(cat branches.sorted) 171 do 172 git rev-parse initial >expect && 173 git show-branch --merge-base initial $branch >actual && 174 test_cmp expect actual || return 1 175 done 176 ' 177 178 test_expect_success 'show branch --merge-base with N arguments' ' 179 git rev-parse initial >expect && 180 git show-branch --merge-base $(cat branches.sorted) >actual && 181 test_cmp expect actual && 182 183 git merge-base $(cat branches.sorted) >actual && 184 test_cmp expect actual 185 ' 186 187 # incompatible options 188 while read combo 189 do 190 test_expect_success "show-branch $combo (should fail)" ' 191 test_must_fail git show-branch $combo 2>error && 192 test_grep -e "cannot be used together" -e "usage:" error 193 ' 194 done <<\EOF 195 --all --reflog 196 --merge-base --reflog 197 --list --merge-base 198 --reflog --current 199 EOF 200 201 # unnegatable options 202 for opt in topo-order date-order reflog 203 do 204 test_expect_success "show-branch --no-$opt (should fail)" ' 205 test_must_fail git show-branch --no-$opt 2>err && 206 test_grep "unknown option .no-$opt." err 207 ' 208 done 209 210 test_expect_success 'error descriptions on non-existent branch' ' 211 cat >expect <<-EOF && 212 error: no branch named '\''non-existent'\'' 213 EOF 214 test_must_fail git branch --edit-description non-existent 2>actual && 215 test_cmp expect actual 216 ' 217 218 test_expect_success 'fatal descriptions on non-existent branch' ' 219 cat >expect <<-EOF && 220 fatal: branch '\''non-existent'\'' does not exist 221 EOF 222 test_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual && 223 test_cmp expect actual && 224 225 cat >expect <<-EOF && 226 fatal: no branch named '\''non-existent'\'' 227 EOF 228 test_must_fail git branch -c non-existent new-branch 2>actual && 229 test_cmp expect actual && 230 test_must_fail git branch -m non-existent new-branch 2>actual && 231 test_cmp expect actual 232 ' 233 234 test_expect_success 'error descriptions on orphan branch' ' 235 test_when_finished git worktree remove -f wt && 236 git worktree add wt --detach && 237 git -C wt checkout --orphan orphan-branch && 238 test_branch_op_in_wt() { 239 test_orphan_error() { 240 test_must_fail git $* 2>actual && 241 test_grep "no commit on branch .orphan-branch. yet$" actual 242 } && 243 test_orphan_error -C wt branch $1 $2 && # implicit branch 244 test_orphan_error -C wt branch $1 orphan-branch $2 && # explicit branch 245 test_orphan_error branch $1 orphan-branch $2 # different worktree 246 } && 247 test_branch_op_in_wt --edit-description && 248 test_branch_op_in_wt --set-upstream-to=ne && 249 test_branch_op_in_wt -c new-branch 250 ' 251 252 test_expect_success 'setup reflogs' ' 253 test_commit base && 254 git checkout -b branch && 255 test_commit one && 256 git reset --hard HEAD^ && 257 test_commit two && 258 test_commit three 259 ' 260 261 test_expect_success '--reflog shows reflog entries' ' 262 cat >expect <<-\EOF && 263 ! [branch@{0}] (0 seconds ago) commit: three 264 ! [branch@{1}] (60 seconds ago) commit: two 265 ! [branch@{2}] (2 minutes ago) reset: moving to HEAD^ 266 ! [branch@{3}] (2 minutes ago) commit: one 267 ---- 268 + [branch@{0}] three 269 ++ [branch@{1}] two 270 + [branch@{3}] one 271 ++++ [branch@{2}] base 272 EOF 273 # the output always contains relative timestamps; use 274 # a known time to get deterministic results 275 GIT_TEST_DATE_NOW=$test_tick \ 276 git show-branch --reflog branch >actual && 277 test_cmp expect actual 278 ' 279 280 test_expect_success '--reflog handles missing reflog' ' 281 git reflog expire --expire=now branch && 282 git show-branch --reflog branch >actual && 283 test_must_be_empty actual 284 ' 285 286 test_done