Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper/staged-git-files-1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
okonet committed Oct 30, 2018
2 parents c4e8a2d + 00047de commit 07fd087
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -21,6 +21,7 @@
}
}
],
"prettier/prettier": "off"
"prettier/prettier": "off",
"node/no-unsupported-features": ["error", "8.6.0"]
}
}
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -207,7 +207,7 @@ Tools like [Prettier](https://prettier.io), ESLint/TSLint, or stylefmt can refor
}
```

Starting from v8, lint-staged will stash you remaining changes (not added to the index) and restore them from stash afterwards if there are partially staged files detected. This allows you to create partial commits with hunks using `git add --patch`. See the [blog post](https://medium.com/@okonetchnikov/announcing-lint-staged-with-support-for-partially-staged-files-abc24a40d3ff)
Starting from v8, lint-staged will stash your remaining changes (not added to the index) and restore them from stash afterwards if there are partially staged files detected. This allows you to create partial commits with hunks using `git add --patch`. See the [blog post](https://medium.com/@okonetchnikov/announcing-lint-staged-with-support-for-partially-staged-files-abc24a40d3ff)

## Examples

Expand Down
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -3,7 +3,11 @@
'use strict'

const pkg = require('./package.json')
require('please-upgrade-node')(pkg)
require('please-upgrade-node')({
engines: {
node: '>=8.6.0'
}
})

const cmdline = require('commander')
const debugLib = require('debug')
Expand Down
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -9,9 +9,6 @@
"Lufty Wiranda <lufty.wiranda@gmail.com>",
"Suhas Karanth <sudo.suhas@gmail.com>"
],
"engines": {
"node": ">=8.6.0"
},
"bin": "index.js",
"files": ["index.js", "src"],
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/getConfig.js
Expand Up @@ -121,12 +121,13 @@ const optRmMsg = (opt, helpMsg) => ` Option ${chalk.bold(opt)} was removed.
*/
function validateConfig(config) {
debug('Validating config')
const exampleConfig = Object.assign({}, defaultConfig, {
const exampleConfig = {
...defaultConfig,
linters: {
'*.js': ['eslint --fix', 'git add'],
'*.css': 'stylelint'
}
})
}

const deprecatedConfig = {
gitDir: () => optRmMsg('gitDir', "lint-staged now automatically resolves '.git' directory."),
Expand Down
6 changes: 4 additions & 2 deletions src/gitWorkflow.js
Expand Up @@ -5,6 +5,7 @@ const execa = require('execa')
const gStatus = require('g-status')
const del = require('del')
const debug = require('debug')('lint-staged:git')
const resolveGitDir = require('./resolveGitDir')

let workingCopyTree = null
let indexTree = null
Expand All @@ -15,7 +16,7 @@ function getAbsolutePath(dir) {
}

async function execGit(cmd, options) {
const cwd = options && options.cwd ? options.cwd : process.cwd()
const cwd = options && options.cwd ? options.cwd : resolveGitDir()
debug('Running git command', cmd)
try {
const { stdout } = await execa('git', [].concat(cmd), {
Expand Down Expand Up @@ -50,7 +51,8 @@ async function getDiffForTrees(tree1, tree2, options) {
}

async function hasPartiallyStagedFiles(options) {
const files = await gStatus(options)
const cwd = options && options.cwd ? options.cwd : resolveGitDir()
const files = await gStatus({ cwd })
const partiallyStaged = files.filter(
file =>
file.index !== ' ' &&
Expand Down
2 changes: 1 addition & 1 deletion src/resolveTaskFn.js
Expand Up @@ -29,7 +29,7 @@ function execLinter(bin, args, execaOptions, pathsToLint) {
debug('args: %O', binArgs)
debug('opts: %o', execaOptions)

return execa(bin, binArgs, Object.assign({}, execaOptions))
return execa(bin, binArgs, { ...execaOptions })
}

const successMsg = linter => `${symbols.success} ${linter} passed!`
Expand Down
2 changes: 1 addition & 1 deletion test/generateTasks.spec.js
Expand Up @@ -89,7 +89,7 @@ describe('generateTasks', () => {
it('should not match non-children files', () => {
const relPath = path.join(process.cwd(), '..')
resolveGitDir.mockReturnValueOnce(relPath)
const result = generateTasks(Object.assign({}, config), files)
const result = generateTasks({ ...config }, files)
const linter = result.find(item => item.pattern === '*.js')
expect(linter).toEqual({
pattern: '*.js',
Expand Down
10 changes: 5 additions & 5 deletions test/gitWorkflow.spec.js
Expand Up @@ -3,28 +3,28 @@
import path from 'path'
import tmp from 'tmp'
import execa from 'execa'
import gitflow from '../src/gitWorkflow'
import { execGit } from '../src/gitWorkflow'

tmp.setGracefulCleanup()

describe('gitWorkflow', () => {
describe('execGit', () => {
it('should execute git in cwd if working copy is not specified', async () => {
await gitflow.execGit(['init', 'param'])
it('should execute git in process.cwd if working copy is not specified', async () => {
await execGit(['init', 'param'])
expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], {
cwd: path.resolve(process.cwd())
})
})

it('should execute git in a given working copy', async () => {
await gitflow.execGit(['init', 'param'], { cwd: 'test/__fixtures__' })
await execGit(['init', 'param'], { cwd: 'test/__fixtures__' })
expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], {
cwd: path.resolve(process.cwd(), 'test', '__fixtures__')
})
})

it('should work with relative paths', async () => {
await gitflow.execGit(['init', 'param'], {
await execGit(['init', 'param'], {
cwd: 'test/__fixtures__'
})
expect(execa).toHaveBeenCalledWith('git', ['init', 'param'], {
Expand Down

0 comments on commit 07fd087

Please sign in to comment.