Skip to content

Commit

Permalink
fix(main): fix exec git error when not a git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
isuke committed Feb 13, 2018
1 parent fc85e4c commit 1f9e9ff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion git-consistent
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const emoji = require('node-emoji')

const templateFileName = '.gitcommit_template'
const definitionsFileName = '.git_consistent'
const projectRoot = execSync(`git rev-parse --show-toplevel 2> /dev/null`).toString().trim()

const black = '\u001b[30m'
const red = '\u001b[31m'
Expand All @@ -32,6 +31,14 @@ const errorColor = red

const version = '0.5.1'

const getProjectRoot = () => {
try {
return execSync(`git rev-parse --show-toplevel 2> /dev/null`).toString().trim()
} catch (_e) {
throw new Error(`Not a git repository`)
}
}

const loadDefinitions = (path) => {
return yaml.safeLoad(fs.readFileSync(path, 'utf8'))
}
Expand Down Expand Up @@ -285,6 +292,7 @@ const main = (program, template, definitions, terms) => {
// Main
//
try {
const projectRoot = getProjectRoot()
const rootPath = projectRoot === "" ? process.env.HOME : projectRoot
const templateFilePath = path.join(rootPath, templateFileName)
const definitionsFilePath = path.join(rootPath, definitionsFileName)
Expand Down

0 comments on commit 1f9e9ff

Please sign in to comment.