Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Pass -z arg to git ls-files & split on null char #2634

Merged
merged 1 commit into from
Sep 13, 2013
Merged

Pass -z arg to git ls-files & split on null char #2634

merged 1 commit into from
Sep 13, 2013

Conversation

jasonmp85
Copy link

It seems a little bit paranoid to assume there might be a newline or tab in a file name, but it's perfectly valid on many systems. When such a character exists in a filename, git ls-files will return something like "file\nname" in its listing, which is problematic because the calling code expects neither the escaped whitespace nor the quotes.

By passing the -z argument, git uses the null character as the separator, never escaping whitespace nor quoting file names.

@jasonmp85
Copy link
Author

The specs all still pass, but I'm at a loss for where to put a test for this functionality (no such test exists or I'd modify it).

I've been making this small change to the gemspec generated by Bundler for my own projects, so I figure I'd safe my future self some time and open a pull request. If a more frequent committer could figure out where best to put the new test I'll add one.

@indirect
Copy link
Member

Does -z work on Windows? One of the reasons we're using $\ is that it works with Windows line separators, too.

@jasonmp85
Copy link
Author

Gah. I guess my build failed. Lemme fix and rewrite this commit.

Getting a coworker to try this out on Windows, will get back with the verdict. I don't see any documentation to the contrary.

@jasonmp85
Copy link
Author

Worked fine for my coworker. I've got a copy-paste error in my commit (these specs take forever so yeah I was lazy. That's what Travis is for, right?) and will fix it today.

It seems a little bit paranoid to assume there might be a newline or
tab in a file name, but it's perfectly valid on many systems. When such
a character exists in a filename, `git ls-files` will return something
like `"file\nname"` in its listing, which is problematic because the
calling code expects neither the escaped whitespace nor the quotes.

By passing the `-z` argument, git uses the null character as the sep-
arator, never escaping whitespace nor quoting file names.

Additionally, I found I had to use the "\x0" syntax to represent the
null character because "\0" is ambiguous in the context of for instance
`String#sub`.
@jasonmp85
Copy link
Author

I don't know why my commit didn't get annotated by Travis (maybe because I rebased and push --forceed?), but it's passing.

@indirect
Copy link
Member

This seems legit. Thanks! 👍

indirect added a commit that referenced this pull request Sep 13, 2013
Pass `-z` arg to git ls-files & split on null char
@indirect indirect merged commit 5d45774 into rubygems:1-3-stable Sep 13, 2013
@jasonmp85
Copy link
Author

Looks like this made it into bundle 1.3 stable but never master?

@indirect
Copy link
Member

indirect commented Jan 3, 2014

We need to merge up from 1-3-stable to 1-5-stable and master, and up from master to 2-0-dev. Hopefully I can pull that off in the next few days.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants