From 1feecbd91eac1b4a30e74f5356b61607d13ce89f Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 22 Nov 2024 20:11:56 +0000 Subject: [PATCH] branches: Escape percent signs in branch names 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 Tested-by: Josip Sokcevic Commit-Queue: Josip Sokcevic --- subcmds/branches.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subcmds/branches.py b/subcmds/branches.py index 08c6389c..b7a45b4a 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py @@ -167,7 +167,10 @@ is shown, then the branch appears in all projects. 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)