Skip to content

Commit

Permalink
branches: Escape percent signs in branch names
Browse files Browse the repository at this point in the history
If a branch name contains a percent sign, it will be interpreted as a placeholder and color.py will fail to format it.

To avoid this, escape the percent signs prior to calling Coloring
method.

Bug: b/379090488
Change-Id: Id019c776bbf8cbed5c101f2773606f1d32c9e057
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/443801
Reviewed-by: Scott Lee <[email protected]>
Tested-by: Josip Sokcevic <[email protected]>
Commit-Queue: Josip Sokcevic <[email protected]>
  • Loading branch information
sokcevicG authored and LUCI committed Dec 3, 2024
1 parent 616e314 commit 1feecbd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion subcmds/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ def _ProcessResults(_pool, _output, results):
else:
published = " "

hdr("%c%c %-*s" % (current, published, width, name))
# A branch name can contain a percent sign, so we need to escape it.
# Escape after f-string formatting to properly account for leading
# spaces.
hdr(f"{current}{published} {name:{width}}".replace("%", "%%"))
out.write(" |")

_RelPath = lambda p: p.RelPath(local=opt.this_manifest_only)
Expand Down

0 comments on commit 1feecbd

Please sign in to comment.