Added getShortHead

This commit is contained in:
joshaber
2015-12-02 16:16:30 -05:00
parent fe4d3601d5
commit aa634570e6
2 changed files with 30 additions and 3 deletions

View File

@@ -397,4 +397,16 @@ describe('GitRepositoryAsync', () => {
expect(relativizedPath).toBe('a/b.txt')
})
})
describe('.getShortHead(path)', () => {
beforeEach(() => {
const workingDirectory = copyRepository()
repo = GitRepositoryAsync.open(workingDirectory)
})
it('returns the human-readable branch name', async () => {
const head = await repo.getShortHead()
expect(head).toBe('master')
})
})
})

View File

@@ -166,9 +166,11 @@ export default class GitRepositoryAsync {
// * `path` An optional {String} path in the repository to get this information
// for, only needed if the repository contains submodules.
//
// Returns a {String}.
getShortHead (path) {
throw new Error('Unimplemented')
// Returns a {Promise} which resolves to a {String}.
getShortHead (_path) {
return this._getRepo(_path)
.then(repo => repo.getCurrentBranch())
.then(branch => branch.shorthand())
}
// Public: Is the given path a submodule in the repository?
@@ -468,6 +470,19 @@ export default class GitRepositoryAsync {
return this._refreshingCount === 0
}
_getRepo (_path) {
if (!_path) return this.repoPromise
return this.isSubmodule(_path)
.then(isSubmodule => {
if (isSubmodule) {
return Git.Repository.open(_path)
} else {
return this.repoPromise
}
})
}
subscribeToBuffer (buffer) {
const bufferSubscriptions = new CompositeDisposable()