Skip to content

Commit 769c987

Browse files
committed
fix(main): fix error occured when first commit (close #3)
#3
1 parent dc7fdde commit 769c987

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

git-consistent

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ try {
9393
}
9494
} catch (e) {
9595
console.error(`${colors.error}${e.message}${colors.reset}`)
96+
e.status ? process.exit(e.status) : process.exit(1)
9697
}

lib/main.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ const colors = require('./colors')
99
// Functions
1010
//
1111
const getCurrentBranchName = () => {
12-
return execSync('git rev-parse --abbrev-ref HEAD')
13-
.toString()
14-
.trim()
12+
try {
13+
return execSync('git rev-parse --abbrev-ref HEAD 2> /dev/null')
14+
.toString()
15+
.trim()
16+
} catch (e) {
17+
// it is First Commit
18+
if (e.status === 128) {
19+
return ''
20+
} else {
21+
throw e
22+
}
23+
}
1524
}
1625

1726
const branchText = (definition) => {

0 commit comments

Comments
 (0)