Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiffSummary strips trailing spaces in file names #796

Closed
yuribro opened this issue May 16, 2022 · 3 comments
Closed

DiffSummary strips trailing spaces in file names #796

yuribro opened this issue May 16, 2022 · 3 comments

Comments

@yuribro
Copy link

yuribro commented May 16, 2022

If there's a file with trailing spaces in its name, DiffSummary returns the file name with the trailing space trimmed.
To reproduce:

echo text > 'a '
git add .

The output of diffSumary:

> await git.diffSummary(['--cached'])
DiffSummary {
  changed: 1,
  deletions: 0,
  insertions: 1,
  files: [
    {
      file: 'a',
      changes: 1,
      insertions: 1,
      deletions: 0,
      binary: false
    }
  ]
}

But calling diff you can see the extra space (on the +++ line, there's a space before \t)

> await git.diff(['--cached'])
'diff --git a/a  b/a \n' +
  'new file mode 100644\n' +
  'index 0000000..8e27be7\n' +
  '--- /dev/null\n' +
  '+++ b/a \t\n' +
  '@@ -0,0 +1 @@\n' +
  '+text\n'
@EllaSharakanski
Copy link

@steveukx Looks like maybe removing the trim() call here should do the trick

@steveukx
Copy link
Owner

@EllaSharakanski the output for diff --stat=4096 pads file names so they appear the same length in the output, so the trim() that removes those can't tell the difference between padding and a file with a trailing space in its name.

I am working on a change to the library to merge the output of both diff --stat and diff --numstat to reliably detect the file names (as supplied by diff --numstat) while still retrieving the file size of binary file changes (only available in diff --stat).

@yuribro thank you for opening the detailed issue - I will update here once a resolution is available.

@steveukx
Copy link
Owner

Hello again. Apologies for the delay in getting back to this one - a new version of simple-git will be published this weekend that will enable you to use git.diffSummary(['--name-stat']) to cater for the files with trailing spaces in their file names.

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

No branches or pull requests

3 participants