Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] vcs_info - git branch with % in it's name



Doron Behar wrote on Mon, 25 Dec 2017 11:33 +0200:
> I think I found a bug within zsh's module vcs_info.
> 
> If a user is in a git repository with a '%' as part of the name of the
> branch and he has '%b' in his prompt, he might get weird results, like:
> 
>  doron   bla9269ello  ~/repos/abcde 
> 
> Instead of:
>  
>  doron   bla%ello  ~/repos/abcde 
>  
> Has anyone encountered this before? I wonder why it happens..

Prompt expansions and zformat both use % as an expando introducer.  This is
basically the same form of bug as doing *«printf(argv[1])» in C.  %h is:

       %h
       %!     Current history event number.

(Incidentally, it is missing from «print -P %<TAB>» completion)

How about the following?  If that is the right fix then the adjacent lines will
need similar tweaking.

diff --git a/Functions/VCS_Info/VCS_INFO_formats b/Functions/VCS_Info/VCS_INFO_formats
index 4d0dd75c2..a46a10286 100644
--- a/Functions/VCS_Info/VCS_INFO_formats
+++ b/Functions/VCS_Info/VCS_INFO_formats
@@ -81,7 +81,7 @@ for i in {1..${#msgs}} ; do
     if VCS_INFO_hook "set-message" $(( $i - 1 )) "${msgs[$i]}"; then
         zformat -f msg ${msgs[$i]}                      \
                         a:${hook_com[action]}           \
-                        b:${hook_com[branch]}           \
+                        b:${hook_com[branch]//'%'/%%}   \
                         c:${hook_com[staged]}           \
                         i:${hook_com[revision]}         \
                         m:${hook_com[misc]}             \

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author