Skip to content

Commit d56225b

Browse files
committed
feat: --force needed only on the woking dir is not clean
No need to clean the entire repo, as long as the working directory is clean enough. resolve #46
1 parent 3d4ee6e commit d56225b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/security-check.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
const { join } = require('path')
12
const fs = require('fs-extra')
23
const git = require('simple-git/promise')
34
const throwError = require('./utils/throw-error')
5+
const isChildPathOf = require('./utils/is-child-path-of')
46

57

68
const isEmpty = async path => {
@@ -17,8 +19,13 @@ const reminder = [
1719

1820
const isWorkDirClean = async path => {
1921
const { files } = await git(path).status()
20-
21-
return !files.length
22+
let toplevel = await git(path).revparse(['--show-toplevel'])
23+
toplevel = toplevel.replace(/\n$/, '')
24+
25+
return !files
26+
.map(file => join(toplevel, file.path))
27+
.filter(isChildPathOf(path))
28+
.length
2229
}
2330

2431
module.exports = async path => {

src/utils/is-child-path-of.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = parent => child => {
2+
if (child === parent) return false
3+
const parentTokens = parent.split('/').filter(i => i.length)
4+
const childTokens = child.split('/').filter(i => i.length)
5+
return parentTokens.every((t, i) => childTokens[i] === t)
6+
}

0 commit comments

Comments
 (0)