git-clean fails to remove a file whose name contains \\, ", or \n, TAB, etc.
Not that it matters (or maybe this is a feature :-), because people who create such files in their working directory deserve what they get, Eh? :-)
But if leaving it, then perhaps git-clean should at least warn that it's not doing its job (i.e. remove the uses of rm's "-f").
To reproduce, run these commands:
nl='
'
git-init > /dev/null && touch "x\\n\"$nl" && git-clean && ls -b
Here's the output I get:
Removing "x\\n\"\n"
.git/ x\\n"\ngit-clean.sh needs to strip off leading and trailing double quotes (easy) as well as convert escapees back to originals (not easy as you might think, in sh) before running rm. Good excuse to rewrite it in perl.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jim" == Jim Meyering <[email protected]> writes:
Jim> Not that it matters (or maybe this is a feature :-), because people Jim> who create such files in their working directory deserve what they Jim> get, Eh? :-)
The problem is the newline in the string, since
git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
while read -r file; dois using newline as a delimiter. Any file with a newline would mess this up.
Not being a shell programming expert, is there a way we could use -z and xargs -0 here instead?
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 8 lines · Randal L. Schwartz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jim" == Jim Meyering <[email protected]> writes:
Jim> Not that it matters (or maybe this is a feature :-), because people Jim> who create such files in their working directory deserve what they Jim> get, Eh? :-)
The problem is the newline in the string, since
Quoted 7 lines
git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" | while read -r file; dois using newline as a delimiter. Any file with a newline would mess this up.
Not being a shell programming expert, is there a way we could use -z and xargs -0 here instead?
Unfortunately read does not have zero-delimited mode (at all). Unfortunately the backquote expansion does not preserve whitespace correctly, so it's not possible to use something like head.
Unfortunately there does not seem to be a way to feed newline to read (without -r flag), because the rules say that '\<NL>' => '' and '\<something>' => '<something>'.
Than I can't think of anything other than xargs -0. Unfortunately that is an external command, which only handles simple commands. So the question becomes how to give it a simple command. Well, there would be two ways:
- A simple command might be:
sh -c 'arbitrarily complex command' dummy arguments...
(the "dummy" will become $0),
so you can simply put the whole loop in single quotes, use for file; do instead of while read -r file; do and be done.
- Reinvoke the program with special argument meaning it should run the inner loop. Ie. add an option --inner-loop option, that would run the inner loop and terminate and use xargs -0 "$0" --inner-loop
Both solutions require exporting all the necessary variables.
Signature · 1 line
Jan 'Bulb' Hudec <[email protected]>
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jan" == Jan Hudec <[email protected]> writes:
Jan> Than I can't think of anything other than xargs -0.
git-ls-files -z .... |
perl -0lne '
$_ is each name here
'
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 8 lines · Randal L. Schwartz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jan" == Jan Hudec <[email protected]> writes:
Jan> Than I can't think of anything other than xargs -0.
git-ls-files -z .... |
perl -0lne '
$_ is each name here
'
Have you seen this?
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Karl" == Karl Hasselström <[email protected]> writes:
Karl> Have you seen this?
Karl> http://xkcd.com/c224.html
Yes. You would be, oh, the 92nd person to point that out to me. :)
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 6 lines · Randal L. Schwartz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Karl" == Karl Hasselström <[email protected]> writes:
Karl> Have you seen this?
Karl> http://xkcd.com/c224.htmlYes. You would be, oh, the 92nd person to point that out to me. :)
Ah well. At least I sent it to the list too, so everyone can have their choice of snickering at the comic, or me, whichever seems silliest. :-)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 8 lines · [email protected] (Randal L. Schwartz) writes:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jim" == Jim Meyering <[email protected]> writes:
Jim> Not that it matters (or maybe this is a feature :-), because people Jim> who create such files in their working directory deserve what they Jim> get, Eh? :-)
The problem is the newline in the string, since
Quoted 7 lines
git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" | while read -r file; dois using newline as a delimiter. Any file with a newline would mess this up.
Not being a shell programming expert, is there a way we could use -z and xargs -0 here instead?
Funny that we had this discussed on this list a few days ago ;-).