Skip to content

Handle case where large file changed in earlier commit - #6

Closed
lyuzashi wants to merge 1 commit into
alex-e-leon:masterfrom
lyuzashi:master
Closed

lyuzashi wants to merge 1 commit into
alex-e-leon:masterfrom
lyuzashi:master

Conversation

@lyuzashi

Copy link
Copy Markdown
Contributor

So sorry @alex-e-leon, I came across another edge case I'd introduced when

  • a particular large file has changed in commits between base and head
  • head did not include that large file as part of the commit

In this case, that large file will not be found in the particular commit that is looked up resulting in an error

Cannot read property 'sha' of undefined

To address this, I've reintroduced passing around the sha of every file that is retrieved by compareCommits and used that as a fallback if the particular commit for comparison does not include that file.

Let me know your thoughts on this.

Test case: (note commit at 1.3.0 of my sample repo does not include a change on the zip)

githubDiff('lyuzashi/github-diff-sample', '1.1.0', '1.3.0')
> [ { filename: 'binary-data.zip',
    patch: undefined,
    status: 'modified',
    header: 'diff --git a/binary-data.zip b/binary-data.zip\n--- a/binary-data.zip\n+++ b/binary-data.zip\n',
    fileA: <Buffer 50 4b 03 04 14 00 08 00 08 00 00 65 95 4b 00 00 00 00 00 00 00 00 00 00 00 00 18 00 10 00 70 65 78 65 6c 73 2d 70 68 6f 74 6f 2d 34 35 31 34 39 30 2e ... >,
    fileB: <Buffer 50 4b 03 04 14 00 08 00 08 00 03 65 95 4b 00 00 00 00 00 00 00 00 00 00 00 00 18 00 10 00 70 65 78 65 6c 73 2d 70 68 6f 74 6f 2d 32 34 36 35 31 39 2e ... > },
  { filename: 'readme.MD',
    patch: '@@ -7,6 +7,6 @@ This repository is a quick test for the following functions of [github-diff](htt\n * Modifying files\n * Renaming files\n \n-This file was modified.\n+This file was modified again.\n \n binary-data.zip was added.',
    status: 'modified',
    header: 'diff --git a/readme.MD b/readme.MD\n--- a/readme.MD\n+++ b/readme.MD\n',
    fileA: '# Sample Repository for GitHub Diff\n\nThis repository is a quick test for the following functions of [github-diff](https://github.com/alex-e-leon/github-diff)\n\n* Removing files\n* Adding files\n* Modifying files\n* Renaming files\n\nThis file was modified.\n\nbinary-data.zip was added.\n',
    fileB: '# Sample Repository for GitHub Diff\n\nThis repository is a quick test for the following functions of [github-diff](https://github.com/alex-e-leon/github-diff)\n\n* Removing files\n* Adding files\n* Modifying files\n* Renaming files\n\nThis file was modified again.\n\nbinary-data.zip was added.\n' } ]

Really hoping to eventually find time to write some unit tests for all these cases.

@alex-e-leon

Copy link
Copy Markdown
Owner

@lyuzashi Sorry for taking so long to get to this PR, I've been on holidays for the last few weeks, and haven't had much internet access either.

Rather than the changes suggested in this PR, I think I've fixed the issue with a small simple change - see my PR here: #7

The summary is that rather than looking for the file in the commit for the sha, just get the file from the tree at that sha instead, which means that it will always exist regardless of whether it was modified in the commit or not.

LMK what you think - and thanks again for your help

@alex-e-leon

Copy link
Copy Markdown
Owner

Fixed in #7

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.

2 participants