Marlon
Marlon

Reputation: 1877

Accent Characters in git diff output

I'm trying to create a script/program to automate my build process. My main goal is to generate a .zip file based on a commit from git. I'm using git diff for that, to output the list of files changed in this commit, I'm using the following command:

git  --no-pager diff --no-renames --name-only --diff-filter=ACM <commit_id>

The problem is when the filename or folder has some portuguese especial chars, they're returned like codes. For Instance, I have a folder called :

db/alterações/2020-04-30.sql

and its returned like that in the list:

db/altera\303\247\303\265es/2020-04-30.sql

How can I make git return the special chars instead of theses codes?

Upvotes: 3

Views: 851

Answers (1)

bk2204
bk2204

Reputation: 76409

Git produces these filenames using the setting of core.quotePath, which defaults to true. When this option is true, bytes with the top bit set are quoted in octal. When the option is false, they are not, but other control characters still are.

Also, if you use -z, Git produces NUL-terminated strings and does not quote characters. This also has the benefit of dealing with newlines and tabs gracefully if they appear in filenames.

So, if your program can handle NUL bytes as terminators, write this:

git  --no-pager diff --no-renames --name-only --diff-filter=ACM -z <commit_id>

and if not, you can write this:

git -c core.quotepath=false --no-pager diff --no-renames --name-only --diff-filter=ACM \
    <commit_id>

Upvotes: 6

Related Questions