forked from todogroup/repolinter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-working-tree.js
More file actions
44 lines (40 loc) · 1.33 KB
/
git-working-tree.js
File metadata and controls
44 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2017 TODO Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
const spawnSync = require('child_process').spawnSync
const Result = require('../lib/result')
// eslint-disable-next-line no-unused-vars
const FileSystem = require('../lib/file_system')
/**
*
* @param {FileSystem} fs A filesystem object configured with filter paths and target directories
* @param {object} options The rule configuration
* @returns {Result} The lint rule result
* @ignore
*/
function gitWorkingTree(fs, options) {
const args = ['-C', fs.targetDir, 'rev-parse', '--show-prefix']
const gitResult = spawnSync('git', args)
const result = new Result('', [], true)
if (gitResult.status === 0) {
const prefix = gitResult.stdout.toString().trim()
if (!prefix) {
result.message =
'The directory is managed with Git, and it is the root directory.'
return result
}
if (options.allowSubDir) {
result.message = 'The sub-directory is managed with Git.'
return result
} else {
result.message =
'The sub-directory is managed with Git, but need to check the root directory.'
result.passed = false
return result
}
} else {
result.message = 'The directory is not managed with Git.'
result.passed = false
return result
}
}
module.exports = gitWorkingTree