Skip to content

fix: git diff filename parsing when filenames contain spaces - #547

Open
Treeniks wants to merge 1 commit into
altsem:masterfrom
Treeniks:master
Open

fix: git diff filename parsing when filenames contain spaces#547
Treeniks wants to merge 1 commit into
altsem:masterfrom
Treeniks:master

Conversation

@Treeniks

Copy link
Copy Markdown

Checklist

  • The modified code has some test-coverage (where applicable).
  • make test is passing (this is what CI runs).
  • New unreleased features/fixes/styling and performance improvements are documented via git: feat: / fix: / style: / perf:. Or e.g. perf(highlighting):.
    See https://github.com/altsem/gitu/blob/master/docs/dev-tooling.md

fixes #499

It seems git adds a tab character behind filenames with spaces in them to clearly differentiate what is still part of the filename, and what is the delimiter for metadata (even when not printing any metadata). Not an issue when the filenames get quoted, but as far as I can tell, they don't by default. This resulted in the git add command including that tab character, which caused an error.

I simply added a new newline_or_tab_or_eof delimiter that is now used instead. I haven't looked into the testing setup, so I didn't write any tests for this.

During debugging, I also noticed that the fmt::Debug implementation on the Parser often fails on the log::trace! call inside newline_or_eof. I think it's because line_end is a byte index for the string slice self.input[line_start..], not for the entire string. So one would probably need something like:

        let line_end = line_start + self.input[line_start..]
            .find('\n')
            .unwrap_or(self.input.len());

However, it still panicked because cursor sometimes didn't land on a proper unicode byte. I guess there is more wrong here, so I left it out of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot Stage Filename With Space

1 participant