Kunal Vashist
Kunal Vashist

Reputation: 2471

NodeGit how to get last commit id of another branch?

I have two branches checked out of my system Master and Dev.

My Working directory is Master from Master I want to push/merge file to dev after knowing the difference.

For say in Master I am working abc.txt file and I want to check the difference between the file present in dev with master. How can I do it?

Getting this error

error while pushing == Error: no reference found for shorthand 'dev' (node:93479) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: no reference found for shorthand 'dev'

Code

differenceCommit(fileName,branchName) {
        return new Promise(function (resolve,reject) {
            let repo,
                changes;
            open("./master")
                .then(function (repoResult) {
                    repo = repoResult;
                    return repo;
                })
                .then(function (commitId) {
                    return repo.getBranchCommit("dev");
                })
                ///Difference Before Push
                .then(function (commit) {
                    return commit.getDiffWithOptions("dev");
                })
                .then(function (diffList) {
                    console.log("************************");
                });
    }

Upvotes: 2

Views: 1224

Answers (1)

Veve
Veve

Reputation: 6758

Add origin/ to the name of the branch:

differenceCommit(fileName,branchName) {
        return new Promise(function (resolve,reject) {
            let repo,
                changes;
            open("./master")
                .then(function (repoResult) {
                    repo = repoResult;
                    return repo;
                })
                .then(function (commitId) {
                    return repo.getBranchCommit("origin/dev");
                })
                ///Difference Before Push
                .then(function (commit) {
                    return commit.getDiffWithOptions("origin/dev");
                })
                .then(function (diffList) {
                    console.log("************************");
                });
    }

Upvotes: 2

Related Questions