Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript nodegit unable to find remote

Folks, I have a branch called user/foo that I'd like to check out from remote. Code:

Git.prototype.refresh = function refresh(branch) {

    var options = {
        credentials: function() {
            return NodeGit.Cred.userpassPlaintextNew(GITHUB_TOKEN, "x-oauth-basic");
        },
        certificateCheck: function() {
            return 1;
        }
    };

    return NodeGit.Repository.open(localPath).then(function (repo) {

        return repo.checkoutBranch(branch, options).then(function (checkoutresult) {

            return repo.fetchAll(options).then(function (result) {
                return Promise.resolve(result);
            }).catch(function (err) {
                console.log('Unable to fetch',err);
                return Promise.reject(new Error(err));
            });
        }).catch(function(err) {
            console.log('checkoutBranch',err);
            return Promise.reject(new Error(err));
        });
    });
};

error:

[Error: Error: Reference 'refs/remotes/user/foo/HEAD' not found]

Am I using checkoutBranch incorrectly? I already have the remote cloned to a local directory, and am trying to switch to a particular branch.

Thanks!

like image 872
Cmag Avatar asked Oct 19 '22 15:10

Cmag


1 Answers

This is copypasta from the nodegit issue

So you can only checkout a local branch. You're trying to checkout a remote. What you'll have to do is get the commit on the remote branch and then use that to create a new branch and then (optionally) set the upstream to track the original remote branch.

At that point you can then check out your newly created local branch.

like image 153
johnhaley81 Avatar answered Oct 27 '22 01:10

johnhaley81