Skip to content

Commit 21e2af1

Browse files
committed
fix: silent false success when git is not present
Add callback function and error check to `execFile`. Fixes conventional-changelog/commitlint#2136
1 parent b5951fb commit 21e2af1

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

packages/git-raw-commits/index.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,31 @@ function gitRawCommits (rawGitOpts, rawExecOpts) {
5353
gitOpts.debug('Your git-log command is:\ngit ' + args.join(' '))
5454
}
5555

56-
let isError = false
57-
5856
const child = execFile('git', args, {
5957
cwd: execOpts.cwd,
6058
maxBuffer: Infinity
59+
}, function (err) {
60+
if (err != null) {
61+
readable.emit('error', err)
62+
}
63+
64+
readable.emit('close')
6165
})
6266

6367
child.stdout
6468
.pipe(split(DELIMITER + '\n'))
6569
.pipe(through(function (chunk, enc, cb) {
6670
readable.push(chunk)
67-
isError = false
6871

6972
cb()
7073
}, function (cb) {
7174
setImmediate(function () {
72-
if (!isError) {
73-
readable.push(null)
74-
readable.emit('close')
75-
}
75+
readable.push(null)
7676

7777
cb()
7878
})
7979
}))
8080

81-
child.stderr
82-
.pipe(through.obj(function (chunk) {
83-
isError = true
84-
readable.emit('error', new Error(chunk))
85-
readable.emit('close')
86-
}))
87-
8881
return readable
8982
}
9083

packages/git-raw-commits/test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ describe('git-raw-commits', function () {
2929
})
3030
.pipe(through(function () {
3131
done('should error')
32-
}, function () {
33-
done('should error')
3432
}))
3533
})
3634

@@ -192,4 +190,24 @@ describe('git-raw-commits', function () {
192190
done()
193191
}))
194192
})
193+
194+
it('should emit an error if git is not available', function (done) {
195+
try {
196+
var path = process.env.PATH
197+
process.env.PATH = ''
198+
199+
gitRawCommits()
200+
.on('error', function (err) {
201+
expect(err).to.be.ok // eslint-disable-line no-unused-expressions
202+
done()
203+
})
204+
.pipe(through(function () {
205+
done('should error')
206+
}, function () {
207+
done('should error')
208+
}))
209+
} finally {
210+
process.env.PATH = path
211+
}
212+
})
195213
})

0 commit comments

Comments
 (0)