nodegit: Error: Reference 'refs/remotes/master/HEAD' not found
Hi, I am trying to implement ‘git pull origin master’ command using nodegit. Used example as base https://github.com/nodegit/nodegit/blob/master/examples/pull.js
var repo;
Git.Repository.init("some/path", 0)
    // git remote add origin REMOTE
    .then(repository => {
        Git.Remote.create(repository, "origin", "sshurl");
        return repository;
    })
    // git pull origin master
    .then(repository => {
        repo = repository;
        return repo.fetch("origin", {
            callbacks: {
                credentials: (url, userName) => {
                    return Git.Cred.sshKeyFromAgent(userName);
                },
                certificateCheck: () => { 
                    return 1;
                },
                transferProgress: info => {
                    return console.log(info.receivedObjects() + ' / ' + info.totalObjects());
                }
            }
        })
    })
    .then(() => {
        return repo.mergeBranches("master", "origin/master");
    })
.git/config:
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
After that I am getting:
Error: Reference 'refs/remotes/master/HEAD' not found
    at Error (native)
What am I doing wrong? Credentials work for sure as I see fetching progress.
About this issue
- Original URL
 - State: open
 - Created 9 years ago
 - Comments: 25 (1 by maintainers)
 
Here is code that works for me. Note that it is not the ideal implementation but it does demonstrate the things missing with an empty clone.
Example usage:
@carlosmn the following triggered something in my head about our use case
For us, we’ve seen this issue when trying to pull when the local master branch has no commits but the remote had a commit added. I understand why our code was failing now with your statement about what
git mergedoes and the fact that this error is a bit of red herring. I just updated our code to create the local branch when the local version is unborn, and all is now good. (the code is a lot simpler too! 😄)The previous code I posted was working around the error, but the symref creation is unnecessary. I just need to handle the edge case for an unborn master branch and not call NodeGit’s
mergeBranchesmethod.Hope this is helpful for the discussion!