From: Joey Hess <id@joeyh.name>
To: git@vger.kernel.org
Subject: infelicities in git hash-object --stdin-paths with special characters
Date: Mon, 2 Dec 2024 13:41:07 -0400 [thread overview]
Message-ID: <Z03xM9AvbUpqXpkI@kitenet.net> (raw)
Apparently "Icon\r" is a common filename on OSX, anyway it's a legal
unix filename. It seems that sending a line containing that filename to
git hash-object --stdin-paths triggers some DOS-style CRLF handling.
Here I am running git version 2.45.2 on Linux.
$ touch Icon^M
$ printf 'Icon\r\n' | git hash-object --stdin-paths
fatal: could not open 'Icon' for reading: No such file or directory
$ echo 'wrong file!' > Icon
$ printf 'Icon\r\n' | git hash-object --stdin-paths
1c43b74a7787621318ee7442eb5a36e32476f326
While looking at builtin/hash-object.c to see why it might do this, I quickly
noticed another odd behavior:
$ touch '"foo"'
$ printf '"foo"\n' | git hash-object --stdin-paths
fatal: could not open 'foo' for reading: No such file or directory
$ touch '"foo'
$ printf '"foo\n' | git hash-object --stdin-paths
fatal: line is badly quoted
The documentation does not seem to mention that quoted lines in
--stdin-paths are at all special. Of course, quoting would be one way to
work around the CRLF problem, if it were documented.
It seems that some parts of git that read filenames from stdin use
strbuf_getline_lf and others use strbuf_getdelim_strip_crlf. There does
not seem to be any consistency, and my impression is any user is best
off using -z, when the command supports it, to avoid the mess.
Given all that, maybe adding -z to hash-object would be a good "fix".
--
see shy jo
next reply other threads:[~2024-12-03 18:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 17:41 Joey Hess [this message]
2024-12-05 9:44 ` infelicities in git hash-object --stdin-paths with special characters Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z03xM9AvbUpqXpkI@kitenet.net \
--to=id@joeyh.name \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).