stackdot / NodeJS-Git-Server

A multi-tenant git server using NodeJS
387 stars 103 forks source link

Read file from server side #19

Open pyprism opened 10 years ago

pyprism commented 10 years ago

Is there any way to read file , commit info etc from git server ?

jutaz commented 10 years ago

Not yet. But in theory you could use node-gitteh to read data from repository. If you are willing to implement this feature, please make a PR, so we can merge it in the master.

bugs181 commented 9 years ago

We've found nodegit to be valuable in this case. For some reason node-gitteh wouldn't do what we wanted. Just keep in mind if you develop your server on a particular machine, it's likely when you push to production that nodegit module will likely need to be recompiled due to architecture incompatibilities.

Here's an example of how we're using nodegit to retrieve the latest commit changes. You can also clone repos, and modify your git repo to your heart's desire.

function gitMessage(gitRawPath, gitCommit, callback) {
  // This function will retrieve the last commit message from a commit # in a git repo.
  var open = nodegit.Repository.open;
  open(gitRawPath)
    .then(function(repo) {
      return repo.getCommit(gitCommit);
    })
    .then(function(commit) {
      if (callback) callback( commit.message() );
    })
    .catch(function(err) { 
      var message = "Error opening git repo \n";
      message    += "Code: `" + err + "` \n";

      webhook.payload.channel = "#git";
      webhook.postDebug(message);
    });
}