# [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages

14 messages from 2021-05-26 to 2021-05-31. Participants: Yuri, Junio C Hamano, Torsten Bögershausen, Jeff King, Bagas Sanjaya, Thomas Guyot.
Thread: https://gitlist.dev/t/55777

## Yuri, 2021-05-26 22:47

Subject: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <f7e2e271-dcec-2886-f33e-62778a429850@rawbw.com>
URL: https://gitlist.dev/e/f7e2e271-dcec-2886-f33e-62778a429850%40rawbw.com

```
I have the file that contains the "∞" character in its name.


When this file was modified, 'git status .' showed it as:

 >    modified:   "file-name-\342\210\236.ext"


It replaced the UTF8 character with its byte representation, and put the 
file name in quotes.


git should show such files without escaping when the terminal is able to 
show UTF8 characters because escaping decreases readability.

$ env | grep TERM
COLORTERM=truecolor
TERM=xterm-256color

$ env | grep LANG
LANG=C.UTF-8

$ env | grep CTYPE
LC_CTYPE=en_US.UTF-8


Thanks,

Yuri


```

## Junio C Hamano, 2021-05-26 23:32

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <xmqq35u9ax5j.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq35u9ax5j.fsf%40gitster.g
In-Reply-To: <f7e2e271-dcec-2886-f33e-62778a429850@rawbw.com>

```
Yuri <yuri@rawbw.com> writes:

> I have the file that contains the "∞" character in its name.

"git config core.quotepath no"?

```

## Yuri, 2021-05-26 23:41

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <6318ccec-ec96-91a8-fd65-85daf4a9a22b@rawbw.com>
URL: https://gitlist.dev/e/6318ccec-ec96-91a8-fd65-85daf4a9a22b%40rawbw.com
In-Reply-To: <xmqq35u9ax5j.fsf@gitster.g>

```
On 5/26/21 4:32 PM, Junio C Hamano wrote:
> "git config core.quotepath no"?


I didn't have the 'core.quotepath' value set. 'git config core.quotepath 
no' changed the behavior to no quoting.

So it looks like the default value of 'core.quotepath' is incorrect: it 
should be based on terminal capabilities.



Yuri



```

## Torsten Bögershausen, 2021-05-27 04:56

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <20210527045628.uvesihyhtqrfyfae@tb-raspi4>
URL: https://gitlist.dev/e/20210527045628.uvesihyhtqrfyfae%40tb-raspi4
In-Reply-To: <6318ccec-ec96-91a8-fd65-85daf4a9a22b@rawbw.com>

```
On Wed, May 26, 2021 at 04:41:38PM -0700, Yuri wrote:
> On 5/26/21 4:32 PM, Junio C Hamano wrote:
> > "git config core.quotepath no"?
>
>
> I didn't have the 'core.quotepath' value set. 'git config core.quotepath no'
> changed the behavior to no quoting.
>
> So it looks like the default value of 'core.quotepath' is incorrect: it
> should be based on terminal capabilities.
>

This are 2 different things.
If you are in a project where only ASCII names are allowed (for whatever reason),
you may want `git config core.quotepath no`, regardless what the terminal can do.

(Beside that, are ther terminals that don't handle UTF-8 these days?)

Any, if you prefer UTF-8 as a default,

git config --global core.quotepath yes

is your friend (like mine)


```

## Jeff King, 2021-05-27 14:02

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <YK+mWZP+sl3zXECx@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YK%2BmWZP%2Bsl3zXECx%40coredump.intra.peff.net
In-Reply-To: <20210527045628.uvesihyhtqrfyfae@tb-raspi4>

```
On Thu, May 27, 2021 at 06:56:28AM +0200, Torsten Bögershausen wrote:

> On Wed, May 26, 2021 at 04:41:38PM -0700, Yuri wrote:
> > On 5/26/21 4:32 PM, Junio C Hamano wrote:
> > > "git config core.quotepath no"?
> >
> >
> > I didn't have the 'core.quotepath' value set. 'git config core.quotepath no'
> > changed the behavior to no quoting.
> >
> > So it looks like the default value of 'core.quotepath' is incorrect: it
> > should be based on terminal capabilities.
> >
> 
> This are 2 different things.
> If you are in a project where only ASCII names are allowed (for whatever reason),
> you may want `git config core.quotepath no`, regardless what the terminal can do.
> 
> (Beside that, are ther terminals that don't handle UTF-8 these days?)

I don't think core.quotepath is just about UTF-8. It is agnostic to the
encoding of the paths, so it is really a question of whether to just
pass through bytes with the high bit set.

So I think the more accurate question is: do the paths in your
repositories generally contain bytes that your terminal can interpret
sensibly?  I'd guess the answer is usually yes, even if you are using
latin1 or similar (or else "ls" would show you mojibake, too).

But there's a follow-on, too: do all the other things which consume
quoted path output likewise handle it? Setting core.quotepath will
impact all parts of Git, including plumbing. So a script that parses
diff-tree output, for example, will see a difference.

I'd guess that most text-processing tools these days are reasonably
happy with high-bit chars. But if we were to flip the default, we might
see regressions with:

  - very old / obscure systems (I'd guess even old versions of GNU tools
    are good, but who knows what Solaris sed will do)

  - some scripting languages (like perl and ruby) have internal strings
    that are encoding-aware, and so they are picky about reading
    high-bit input from a descriptor, especially if it isn't utf8.
    The fix is usually easy-ish, but may be a surprise for some folks
    (OTOH, I can imagine it fixes bugs in sloppily-written scripts which
    did not anticipate the incoming filenames being quoted ;) ).

As Git is used more and more internationally, I suspect the value of
defaulting core.quotepath=no increases. And as time goes on and people
tend to standardize on utf8-aware tools and environments, the risk of
doing so decreases. So while core.quotepath=yes was a conservative
choice in 2007, it might be time to look at switching.

> Any, if you prefer UTF-8 as a default,
> 
> git config --global core.quotepath yes
> 
> is your friend (like mine)

Just a nit/clarification for other readers, but I think you have yes/no
flipped here and earlier in your message.

-Peff

```

## Yuri, 2021-05-27 20:50

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <4dd22f16-72f0-a28a-8be0-aec622acf0d3@rawbw.com>
URL: https://gitlist.dev/e/4dd22f16-72f0-a28a-8be0-aec622acf0d3%40rawbw.com
In-Reply-To: <YK+mWZP+sl3zXECx@coredump.intra.peff.net>

```
It's not clear from the conversation if git reads terminal capabilities 
at all.


But the default behavior, without any options set, should be to read 
terminal capabilities, and write non-ASCII characters verbatim when 
terminal supports this and escape them when terminal doesn't support them.

Current default behavior appears to be to always escape non-ASCII 
characters.


Then options can change this basic behavior according to user's choice.



Yuri



```

## Bagas Sanjaya, 2021-05-28 04:39

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <50e2780a-21f3-499f-7960-76bf24f550f0@gmail.com>
URL: https://gitlist.dev/e/50e2780a-21f3-499f-7960-76bf24f550f0%40gmail.com
In-Reply-To: <4dd22f16-72f0-a28a-8be0-aec622acf0d3@rawbw.com>

```
On 28/05/21 03.50, Yuri wrote:
> It's not clear from the conversation if git reads terminal capabilities 
> at all.
> 
> 
> But the default behavior, without any options set, should be to read 
> terminal capabilities, and write non-ASCII characters verbatim when 
> terminal supports this and escape them when terminal doesn't support them.
> 
> Current default behavior appears to be to always escape non-ASCII 
> characters.

So the current default is only supports ASCII, and escape other 
characters, right?

-- 
An old man doll... just what I always wanted! - Clara

```

## Yuri, 2021-05-28 04:45

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <6fef4b1e-1ec7-b697-c311-59caf6408b29@rawbw.com>
URL: https://gitlist.dev/e/6fef4b1e-1ec7-b697-c311-59caf6408b29%40rawbw.com
In-Reply-To: <50e2780a-21f3-499f-7960-76bf24f550f0@gmail.com>

```
On 5/27/21 9:39 PM, Bagas Sanjaya wrote:
> So the current default is only supports ASCII, and escape other 
> characters, right?


It appears this way.


Yuri


```

## Torsten Bögershausen, 2021-05-29 09:27

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <20210529092752.kifzqt3haddzgsob@tb-raspi4>
URL: https://gitlist.dev/e/20210529092752.kifzqt3haddzgsob%40tb-raspi4
In-Reply-To: <6fef4b1e-1ec7-b697-c311-59caf6408b29@rawbw.com>

```
On Thu, May 27, 2021 at 09:45:53PM -0700, Yuri wrote:
> On 5/27/21 9:39 PM, Bagas Sanjaya wrote:
> > So the current default is only supports ASCII, and escape other
> > characters, right?
>
>
> It appears this way.
>

Yes, that is how it is.

After reading the wiki here:

https://wiki.gentoo.org/wiki/UTF-8

(There are many other web pages as well)

I am not sure that there is a reliable way for Git to detect, if the
terminal is capable of handling UTF-8.
This should work reliable under Linux, Windows, Mac and all the supported
Unix-ish platforms.

Beside that, the outputs of git commands can be feed into other programs
via a pipe usning  "|"  on the command line or redirectet to a file.

And what is a terminal ?
We need to consider that we run programs like `less` or `more´ which
need to be UTF-8 compatble.

Most of them are probably UTF-8 compliant (and LANG is set to xx.UTF-8)
these days.
And most repositories have been feed with filenames encoded in  UTF-8 as well.

Having said that, the default could be switched some day in the future.
Before that is "save", there may be a transition phase,
where users are warned that the default may change.
Scripts calling git need to use `git -c core.quotepath=yes`, or no,
whatever input they expect.

Sorry for the longish answer.
Changing one thing for some users may effect hundrets, thousands or millions
of other users later, cause surprises, need debugging and fixing effort.

Does someone wants to come up with a patch that anounces a possible change ?




```

## Jeff King, 2021-05-30 21:44

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <YLQHPu0bIy4qHEWP@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YLQHPu0bIy4qHEWP%40coredump.intra.peff.net
In-Reply-To: <20210529092752.kifzqt3haddzgsob@tb-raspi4>

```
On Sat, May 29, 2021 at 11:27:52AM +0200, Torsten Bögershausen wrote:

> I am not sure that there is a reliable way for Git to detect, if the
> terminal is capable of handling UTF-8.
> This should work reliable under Linux, Windows, Mac and all the supported
> Unix-ish platforms.

Yeah, I'm not sure how such a check would be done. On most Linux systems
I've seen, $LANG will mention "en_US.UTF-8" or similar. But I've no idea
how portable that convention is, not to mention that people may have
more complex setups anyway (e.g., not setting $LANG but setting some of
LC_*).

But more importantly, this is not even a UTF-8 problem. It is "can your
terminal do something sensible with high-bit characters in filenames of
your repositories". We don't know the encoding of those filenames (and
you may even have a mix).

(And likewise "terminal" here is really "whatever consumes Git's output,
be it the terminal or some program you've piped to).

> Having said that, the default could be switched some day in the future.
> Before that is "save", there may be a transition phase,
> where users are warned that the default may change.
> Scripts calling git need to use `git -c core.quotepath=yes`, or no,
> whatever input they expect.

Yes. If we're going to do anything, I think it would be to say "most
terminals and programs deal with high-bit characters OK these days, so
switching the default is more likely to fix things than break them".

I suspect most scripts would be OK either way. They need to handle
maybe-quoted filenames already, so it is really just a question of
whether the consuming program is OK with the high bits. If so, we could
probably get away with just a mention in the release notes, rather than
an annoying transition phase (which is likely to simply confuse most
users, who are unaware of the issue entirely).

But I'd feel more confident if whoever proposes such a change does some
research on how piping such names into common tools and scripting
languages works (both for utf8 and non-utf8 names).

-Peff

```

## Yuri, 2021-05-30 21:55

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <481fbc88-3e7d-6b00-0997-1a80b87a637d@rawbw.com>
URL: https://gitlist.dev/e/481fbc88-3e7d-6b00-0997-1a80b87a637d%40rawbw.com
In-Reply-To: <YLQHPu0bIy4qHEWP@coredump.intra.peff.net>

```
On 5/30/21 2:44 PM, Jeff King wrote:
> Yeah, I'm not sure how such a check would be done. On most Linux systems
> I've seen, $LANG will mention "en_US.UTF-8" or similar. But I've no idea
> how portable that convention is, not to mention that people may have
> more complex setups anyway (e.g., not setting $LANG but setting some of
> LC_*).


When 'locale charmap' prints 'UTF-8' the terminal can be assumed to be 
able to accept UTF-8 characters.

'locale charmap', I think, determines this only based on environment 
variables.



Yuri


```

## Junio C Hamano, 2021-05-30 22:23

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <xmqqmtsb2757.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqmtsb2757.fsf%40gitster.g
In-Reply-To: <YLQHPu0bIy4qHEWP@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> Yes. If we're going to do anything, I think it would be to say "most
> terminals and programs deal with high-bit characters OK these days, so
> switching the default is more likely to fix things than break them".

Amen to that.  The conservative setting was from v1.5.3 days in
2007, and it would be highly disappointing if the situation hasn't
changed in the 14 years.

```

## Thomas Guyot, 2021-05-31 01:14

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <c1afaf46-0425-110b-6303-f68d3f994b7f@gmail.com>
URL: https://gitlist.dev/e/c1afaf46-0425-110b-6303-f68d3f994b7f%40gmail.com
In-Reply-To: <481fbc88-3e7d-6b00-0997-1a80b87a637d@rawbw.com>

```
On 2021-05-30 17:55, Yuri wrote:
> On 5/30/21 2:44 PM, Jeff King wrote:
>> Yeah, I'm not sure how such a check would be done. On most Linux systems
>> I've seen, $LANG will mention "en_US.UTF-8" or similar. But I've no idea
>> how portable that convention is, not to mention that people may have
>> more complex setups anyway (e.g., not setting $LANG but setting some of
>> LC_*).
> 
> 
> When 'locale charmap' prints 'UTF-8' the terminal can be assumed to be
> able to accept UTF-8 characters.
> 
> 'locale charmap', I think, determines this only based on environment
> variables.
> 

Hi Yuri,

Even if the terminal supports UTF8, will it print it properly? The font
used could have no or minimal utf8 support. Even when it's supported,
some characters might look alike and this could have undesired
consequences (ex accidentally switching from a normal space to a
non-break space while renaming a file that has spaces...).

I believe repos with utf8 files are rare enough and it could be left to
the user to select whenever to use utf8 or not... An option like "auto"
or "detect" could make it automatic but I'm not convinced it should be
the default.


Oh, and looking at "locale charmap", it doesn't check the terminal
capabilities at all - it just prints the charmap based on LC_ALL or
LC_CTYPE value, or default if they're unset. It doesn't mater what
terminal you're on...

Regards,

--
Thomas

```

## Bagas Sanjaya, 2021-05-31 03:35

Subject: Re: [BUG REPORT] File names that contain UTF8 characters are unnecessarily escaped in 'git status .' messages
Message-ID: <ec3adb99-ba20-8db6-4bff-eae7524e6361@gmail.com>
URL: https://gitlist.dev/e/ec3adb99-ba20-8db6-4bff-eae7524e6361%40gmail.com
In-Reply-To: <c1afaf46-0425-110b-6303-f68d3f994b7f@gmail.com>

```
On 31/05/21 08.14, Thomas Guyot wrote:
> Even if the terminal supports UTF8, will it print it properly? The font
> used could have no or minimal utf8 support. Even when it's supported,
> some characters might look alike and this could have undesired
> consequences (ex accidentally switching from a normal space to a
> non-break space while renaming a file that has spaces...).

On Linux distributions, Noto and DejaVu fonts are often installed as 
default fonts, because Noto has almost complete Unicode coverage and 
DejaVu Mono become goto monospace font.

And yeah, we steer clear of using non-monospace fonts (either serif or 
sans serif), because many terminal-only programs depend on text 
alignment which often can be achieved only with monospace fonts, and 
reading texts on terminal screen is vertical-oriented as opposed to 
horizontal-oriented texts like books.

-- 
An old man doll... just what I always wanted! - Clara

```
