FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

"Error: Reference 'refs/heads/master' not found " when create commit in a empty repo · Issue #213 · nodegit/nodegit · GitHub

Repository navigation

"Error: Reference 'refs/heads/master' not found " when create commit in a empty repo #213

Description

Hi, I have init a repo with the code:

git.Repo.init(resourcePath,false,function(initReporError, repo){
    if (initReporError) 
      throw initReporError;
    console.log("Repo init : "+repo);
}

Then I create commit with the code:

git.Repo.open(path.resolve(__dirname, '../.git'), function(openReporError, repo) {
  if (openReporError) throw openReporError;

    //add the file to the index...
    repo.openIndex(function(openIndexError, index) {
      if (openIndexError) throw openIndexError;

      index.read(function(readError) {
        if (readError) throw readError;

        index.addByPath(fileName, function(addByPathError) {
          if (addByPathError) throw addByPathError;

          index.write(function(writeError) {
            if (writeError) throw writeError;

            index.writeTree(function(writeTreeError, oid) {
              if (writeTreeError) throw writeTreeError;

              //get HEAD
              git.Reference.oidForName(repo, 'HEAD', function(oidForName, head) {
                if (oidForName) throw oidForName;

                //get latest commit (will be the parent commit)
                repo.getCommit(head, function(getCommitError, parent) {
                  if (getCommitError) throw getCommitError;
                  var author = git.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60);
                  var committer = git.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90);

                  //commit
                  repo.createCommit('HEAD', author, committer, 'message', oid, [parent], function(error, commitId) {
                    console.log("New Commit:", commitId.sha());
                  });
                });
              });
            });
          });
        });
      });
    });
  });

It says "Error: Reference 'refs/heads/master' not found".
I can run git add/git commit manually and it will create refs/heads/master. But the code cannot.
So what can I do for this? Thanks very much.

Activity

  1. maxkorp commented on Nov 21, 2014

    Collaborator

    I suspect this is working now, but I'll make sure and add any tests as well as an example.

  2. self-assigned this
    on Nov 21, 2014
  3. maxkorp commented on Nov 21, 2014

    Collaborator

    Ah, the actual issue here is that you're getting the head commit, and in a new repo there isnt a head commit. try going into a new directory and initializing a repo and then call git log to see an error, or git show-ref to see there are 0 references (so you cant get head).
    Either way, I've built an example for this, which I'll have in soon.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL