Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix jog/diff in nodegit WIP
  • Loading branch information
squarti committed Feb 22, 2016
1 parent b6d89e3 commit f21c262
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 256 deletions.
2 changes: 2 additions & 0 deletions modules/orionode/lib/git.js
Expand Up @@ -125,6 +125,8 @@ function Git(options) {
add.putStage(workspaceDir, fileRoot, req, res, next, rest);
} else if (rest.indexOf("config/") === 0) {
config.putConfig(workspaceDir, fileRoot, req, res, next, rest);
} else if (rest.indexOf("commit/") === 0) {
commit.putCommit(workspaceDir, fileRoot, req, res, next, rest);
} else {
// Would 501 be more appropriate?
writeError(403, res);
Expand Down
42 changes: 23 additions & 19 deletions modules/orionode/lib/git/branches.js
Expand Up @@ -14,9 +14,30 @@ var git = require('nodegit');
var fs = require('fs');
var async = require('async');

function branchJSON(ref, fileDir) {
var branchURL = ref.name().split("/").join("%252F");
var branchName = ref.name().replace("refs/heads/", "");
var isCurrent = ref.isHead() ? true : false;

return {
"CloneLocation": "/gitapi/clone"+ fileDir,
"CommitLocation": "/gitapi/commit/" + branchURL + fileDir,
"Current": isCurrent,
"DiffLocation": "/gitapi/diff/" + branchName + fileDir,
"FullName": "refs/heads/" + branchName,
"HeadLocation": "/gitapi/commit/HEAD" + fileDir,
"LocalTimeStamp": 1424471958000, //hardcoded local timestamp
"Location": "/gitapi/branch/" + branchURL + fileDir,
"Name": branchName,
"RemoteLocation": [],
"TreeLocation": "/gitapi/tree" + fileDir + "/" + branchURL,
"Type": "Branch"
};
}

function getBranches(workspaceDir, fileRoot, req, res, next, rest) {
var repoPath = rest.replace("branch/file/", "");
var fileDir = /file/ + repoPath;
var fileDir = api.join(fileRoot, repoPath);
repoPath = api.join(workspaceDir, repoPath);

var theRepo;
Expand All @@ -30,24 +51,7 @@ function getBranches(workspaceDir, fileRoot, req, res, next, rest) {
.then(function(referenceList) {
referenceList.forEach(function(ref) {
if (ref.isBranch()) {
var branchURL = ref.name().split("/").join("%252F");
var branchName = ref.name().replace("refs/heads/", "");
var isCurrent = ref.isHead() ? true : false;

branches.push({
"CloneLocation": "/gitapi/clone"+ fileDir,
"CommitLocation": "/gitapi/commit/" + branchURL + fileDir,
"Current": isCurrent,
"DiffLocation": "/gitapi/diff/" + branchName + fileDir,
"FullName": "refs/heads/" + branchName,
"HeadLocation": "/gitapi/commit/HEAD" + fileDir,
"LocalTimeStamp": 1424471958000, //hardcoded local timestamp
"Location": "/gitapi/branch/" + branchName + fileDir,
"Name": branchName,
"RemoteLocation": [],
"TreeLocation": "/gitapi/tree" + fileDir + "/" + branchName,
"Type": "Branch"
});
branches.push(branchJSON(ref, fileDir));
}
});

Expand Down

0 comments on commit f21c262

Please sign in to comment.