mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add getPath helper
This commit is contained in:
committed by
Corey Johnson
parent
cbba58c30e
commit
8e8ab4ff94
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user