diff --git a/git-consistent b/git-consistent index 0405d39..e015b71 100755 --- a/git-consistent +++ b/git-consistent @@ -41,7 +41,7 @@ const setOptions = (program, definitions, terms) => { const optionName = term == 'subject' ? `-m, --${term}` : `--${term}` const valueStr = definition.required ? `<${term}>` : `[${term}]` const defaultValue = definition.default - if (type !== 'variable') program.option(`${optionName} ${valueStr}`, definition.description, defaultValue) + if (! ['variable', 'branch'].includes(type)) program.option(`${optionName} ${valueStr}`, definition.description, defaultValue) return setOptions(program, definitions, _.tail(terms)) } } diff --git a/lib/main.js b/lib/main.js index 0d49c92..f6d6d60 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,6 +62,19 @@ const inputText = (term, _definition) => { return values.join("\n").trim() } +const getCurrentBranchName = () => { + return execSync("git rev-parse --abbrev-ref HEAD").toString().trim() +} + +const branchText = (_term, definition) => { + const currentBranchName = getCurrentBranchName() + const regExp = new RegExp(definition.regExp) + const matchNum = definition.regExpMatchNum || 1 + const match = currentBranchName.match(regExp) + const value = match ? match[matchNum] : '' + return value +} + const input = (term, definition) => { const type = definition.type let inputValue @@ -75,6 +88,9 @@ const input = (term, definition) => { case 'text': inputValue = inputText(term, definition) break + case 'branch': + inputValue = branchText(term, definition) + break case 'variable': break default: