Skip to content

Instantly share code, notes, and snippets.

@xaviervia
Created January 4, 2017 16:59
Show Gist options
  • Save xaviervia/ba9f2e04c54132f150dc674eb2a1ec8f to your computer and use it in GitHub Desktop.
Save xaviervia/ba9f2e04c54132f150dc674eb2a1ec8f to your computer and use it in GitHub Desktop.
Task for getting the current branch name as a Flux action
const Task = require('data.task')
const {Repository, Branch} = require('nodegit')
const {cond, is, T} = require('ramda')
const currentBranch = () =>
new Task((rej, res) =>
Repository.open('.')
.then(repo => repo.getCurrentBranch()
.then(branch => Branch.name(branch).then(name => res(name))))
.catch(() => res()))
.map(cond([
[is(String), name => ({
type: 'ADD_BRANCH',
payload: name.trim()
})],
[T, () => ({})]
]))
module.exports = currentBranch
if (process.argv[1] === __filename) {
currentBranch().fork(console.error, console.log)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment