Created
January 4, 2017 16:59
-
-
Save xaviervia/ba9f2e04c54132f150dc674eb2a1ec8f to your computer and use it in GitHub Desktop.
Task for getting the current branch name as a Flux action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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