Add getPath helper

This commit is contained in:
Kevin Sawicki
2012-10-25 15:20:12 -07:00
committed by Corey Johnson
parent cbba58c30e
commit 8e8ab4ff94
4 changed files with 34 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ var $git = {};
native function getRepository(path);
native function getHead();
native function getPath();
function GitRepository(path) {
var repo = getRepository(path);
@@ -12,5 +13,6 @@ var $git = {};
}
GitRepository.prototype.getHead = getHead;
GitRepository.prototype.getPath = getPath;
this.GitRepository = GitRepository;
})();

View File

@@ -20,6 +20,13 @@ class GitRepository : public CefBase {
git_repository_free(repo);
}
CefRefPtr<CefV8Value> GetPath() {
if (exists)
return CefV8Value::CreateString(git_repository_path(repo));
else
return CefV8Value::CreateNull();
}
CefRefPtr<CefV8Value> GetHead() {
if (!exists)
return CefV8Value::CreateNull();
@@ -65,6 +72,13 @@ bool Git::Execute(const CefString& name,
retval = userData->GetHead();
return true;
}
if (name == "getPath") {
GitRepository *userData = (GitRepository *)object->GetUserData().get();
retval = userData->GetPath();
return true;
}
return false;
}

View File

@@ -2,6 +2,19 @@ Git = require 'git'
describe "Git", ->
describe "getPath()", ->
it "returns the repository path for a working directory file path", ->
repo = new Git(require.resolve('fixtures/git/nohead.git/HEAD'))
expect(repo.getPath()).toBe require.resolve('fixtures/git/nohead.git') + '/'
repo = new Git(require.resolve('fixtures/git/master.git/HEAD'))
expect(repo.getPath()).toBe require.resolve('fixtures/git/master.git') + '/'
it "returns the repository path for a repository path", ->
repo = new Git(require.resolve('fixtures/git/nohead.git'))
expect(repo.getPath()).toBe require.resolve('fixtures/git/nohead.git') + '/'
repo = new Git(require.resolve('fixtures/git/master.git'))
expect(repo.getPath()).toBe require.resolve('fixtures/git/master.git') + '/'
describe "getHead()", ->
it "returns null for a empty repository", ->
repo = new Git(require.resolve('fixtures/git/nohead.git'))

View File

@@ -1,11 +1,12 @@
module.exports =
class Git
constructor: (@repoPath) ->
@repo = new GitRepository(@repoPath)
constructor: (path) ->
@repo = new GitRepository(path)
getHead: ->
@repo.getHead() || ''
getPath: -> @repo.getPath()
getHead: -> @repo.getHead() || ''
getShortHead: ->
head = @getHead()