Search code examples
node.jsgitgitlablibgit2nodegit

Nodegit clone causes “No Content-Type header in response” error


I'm having an issue with nodegit on CentOS 6.7. On our Windows development environment, I'm able to clone/push/pull from remote just fine using nodegit.

On CentOS, however, I get the following error on clone:

No Content-Type header in response

We're not using Apache, just the standard GitLab rpm. GitLab is working fine on the CentOS box as well - I am able to pull and push successfully from Git Bash. Unfortunately, I need to do this programmatically via nodegit, and it's not working.

I'd prefer to not have to resort to CURL if possible - nodegit really seemed like a more dignified option for my project.

It should be noted that I'm using basic HTTP user/password for authorization on our Gitlab instance, because:

  • gitlab and all the programmatic git stuff is hidden on the server-side, and
  • this is a proof of concept to see if a nodegit/gitlab solution is even feasible.

Here is the function that attempts the clone - it works great on Windows:

function pushUserUpdatesToGit(req, res, user, myItem, localPath) {
    var repo, index, oid, remote,
    userCreds = {
        credentials: function() {
            return nodegit.Cred.userpassPlaintextNew(user.username, user.pwd);
        }
    },
    authStuff = {
        remoteCallbacks: {
            credentials: userCreds.credentials,
            certificateCheck: function() { return 1;  }
        }
    };

    return nodegit.Clone.clone(myItem.GitLabRepoPath, localPath, authStuff)
        .then(function(theRepo) {
            repo = theRepo; // save it to reference in any callback we feel like
        }, function (err) {
            console.log("Error cloning repo: " + err );
            return handleError(res, err);
        }
    ).then(function() {
        return repo.openIndex();
    }, function (err) {
        return handleError(res, err);
    })
    // Some exciting stuff happens in here that I won't bore you all with
    .catch(function(error) {
        console.log("ERROR DOING GIT STUFF: " + error);
        return handleError(res, error);
    }).done(function() {
        console.log("done with git stuff");
        return res.json(200, myItem);
    });
}

Solution

  • It seems like you get this error because your git server response is not supporting the Smart HTTP (https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP).

    By default the nginx configuration of gitlab is supporting this. Are you by any chance running the included nginx setup of gitlab behind a reverse proxy?

    If not and you are not using the included nginx setup from gitlab, this might help: https://gist.github.com/massar/9399764