mirror of
https://github.com/atom/atom.git
synced 2026-02-02 10:45:14 -05:00
Added .getReferences
This commit is contained in:
@@ -470,4 +470,19 @@ describe('GitRepositoryAsync', () => {
|
||||
expect(hasBranch).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.getReferences(path)', () => {
|
||||
let workingDirectory
|
||||
beforeEach(() => {
|
||||
workingDirectory = copyRepository()
|
||||
repo = GitRepositoryAsync.open(workingDirectory)
|
||||
})
|
||||
|
||||
it('returns the heads, remotes, and tags', async () => {
|
||||
const {heads, remotes, tags} = await repo.getReferences()
|
||||
expect(heads.length).toBe(1)
|
||||
expect(remotes.length).toBe(0)
|
||||
expect(tags.length).toBe(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -264,12 +264,28 @@ export default class GitRepositoryAsync {
|
||||
// * `path` An optional {String} path in the repository to get this information
|
||||
// for, only needed if the repository has submodules.
|
||||
//
|
||||
// Returns an {Object} with the following keys:
|
||||
// Returns a {Promise} which resolves to an {Object} with the following keys:
|
||||
// * `heads` An {Array} of head reference names.
|
||||
// * `remotes` An {Array} of remote reference names.
|
||||
// * `tags` An {Array} of tag reference names.
|
||||
getReferences (_path) {
|
||||
throw new Error('Unimplemented')
|
||||
return this._getRepo(_path)
|
||||
.then(repo => repo.getReferences(Git.Reference.TYPE.LISTALL))
|
||||
.then(refs => {
|
||||
const heads = []
|
||||
const remotes = []
|
||||
const tags = []
|
||||
for (const ref of refs) {
|
||||
if (ref.isTag()) {
|
||||
tags.push(ref.name())
|
||||
} else if (ref.isRemote()) {
|
||||
remotes.push(ref.name())
|
||||
} else if (ref.isBranch()) {
|
||||
heads.push(ref.name())
|
||||
}
|
||||
}
|
||||
return {heads, remotes, tags}
|
||||
})
|
||||
}
|
||||
|
||||
// Public: Returns the current {String} SHA for the given reference.
|
||||
|
||||
Reference in New Issue
Block a user