Skip to content

DiffList is not returned #1359

Open
Open

Description

@eliranmal

it seems that both Diff.treeToTree and Tree#diff fail to return a DiffList, but instead return a Diff object.

the documentation states that they should, so i'm wondering - is DiffList not supported anymore? was it replaced by another type?

Activity

  1. eliranmal commented on Aug 24, 2017

    @eliranmal
    Author

    here's a code snippet, to put it in context:

    let repository;
    
    Git.Repository.open(gitRoot)
        .then(repo => {
            repository = repo;
            return repo;
        })
        .then((repo) => {
            return Promise.all([
                repo.getHeadCommit(),
                repo.getMasterCommit(),
            ])
        })
        .then(([head, master]) => {
            if (!master.id().equal(head.id())) {
                return Promise.all([
                    head.getTree(),
                    master.getTree(),
                ])
            }
            throw new Error ('no diff!');
        })
        .then(([headTree, masterTree]) => {
            
            // both of these will return a Diff, not a DiffList:
            
            // return Git.Diff.treeToTree(repository, headTree, masterTree);
            return headTree.diff(masterTree);
        })
        .then(list => {
            list.forEach((v, k) => { // --> TypeError: list.forEach is not a function
                console.log(`v: ${v}, k: ${k}`);
            });
        })
    
  2. mariecl commented on Sep 5, 2017

    @mariecl

    I am facing the same issue with very similar code.

  3. rcjsuen commented on Sep 6, 2017

    @rcjsuen
    Member

    I can run diff-commit.js just fine so I don't think it's broken.

    Commit's getDiff function will return a Diff[] so there isn't a problem there.

  4. eliranmal commented on Oct 10, 2017

    @eliranmal
    Author

    @rcjsuen - perhaps Commit's API returns an array of Diffs, but that's not what this issue is about.

    the issue here is other API entries (namely Diff.treeToTree and Tree#diff) that are either poorly documented or flat out fail to return their declared return type (i.e. DiffList).

  5. rcjsuen commented on Oct 10, 2017

    @rcjsuen
    Member

    @eliranmal In your original comment, you mentioned:

    by the way, that also means that the "diff-commits" example is broken, as it iterates over such list.

    I was merely trying to clarify that the example is not exactly broken as it runs just fine. Perhaps it is misleading but it does work and run.

  6. eliranmal commented on Oct 26, 2017

    @eliranmal
    Author

    @rcjsuen i see. well, the reason it works is that it calls a different API than the ones this issue regards.

    in my case, the diff-commits example implementation was not working at the time (perhaps due to other reasons). i will edit the main comment accordingly, as this seems not to break this example after all.

    thanx for the clarification :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions