mirror of
https://github.com/atom/atom.git
synced 2026-02-02 18:55:17 -05:00
Added getShortHead
This commit is contained in:
@@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user