Skip to content

Commit

Permalink
allowed to add custom file on commit task
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroX-DG committed Aug 23, 2018
1 parent ca38788 commit 17252bb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const cli = meow(help, {
highlight: {
type: 'boolean',
alias: 'hl'
},
files: {
type: 'boolean',
alias: 'cf'
}
}
})
Expand Down
15 changes: 15 additions & 0 deletions src/git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ function commit (message) {
})
}

function addFiles (files) {
files = typeof files === 'string' ? [files] : files
const commitCommand = `git add ${files.join(' ')}`
return new Promise((resolve, reject) => {
exec(commitCommand, (error, stdout, stderr) => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}

function getLastCommitDetails () {
const getOutputCommand =
'git log --format="%Cgreen%h%Creset %s %C(bold blue)<%an>%Creset" -n 1'
Expand Down Expand Up @@ -70,6 +84,7 @@ function getLastCommitFiles () {

module.exports = {
commit,
addFiles,
getLastCommitDetails,
isNothingtoCommit,
getLastCommitFiles,
Expand Down
1 change: 1 addition & 0 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Render {
}

drawFileList (files) {
log({ prefix: ' ', message: 'Commited files:' })
const tree = []
;[...files].forEach(file => {
const parts = file.split(path.sep)
Expand Down
7 changes: 6 additions & 1 deletion src/task-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TaskAPI {
* @param {*} input
* @memberof TaskAPI
*/
commitTask (input) {
commitTask (input, withCustomFiles) {
const project = input[0]
let taskId = input[1]
const task = this.getTask(project, taskId)
Expand All @@ -143,6 +143,11 @@ class TaskAPI {
if (nothingToCommit) {
render.logError(getMessage(errors.NOTHING_TO_COMMIT))
} else {
if (withCustomFiles) {
git.addFiles(input.slice(2))
} else {
git.addFiles('.')
}
git
.commit(task.message)
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/task-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TaskManager = (flags, input) => {
}

if (flags.commit) {
return api.commitTask(input)
return api.commitTask(input, flags.files)
}

if (flags.list) {
Expand Down

0 comments on commit 17252bb

Please sign in to comment.