Skip to content

Commit

Permalink
feat: only hide/restore unstaged modifications to partially staged files
Browse files Browse the repository at this point in the history
This change simplifies and speeds up the git workflow by restoring the backup stash before running tasks, and only doing diff/apply to files with both staged and unstaged changes. It also means that a file with only unstaged changes will be present on disk while the tasks are running, so for example unstaged edits to eslint rules will still apply.  This can be considered a fix because the behaviour changed from v9->v10, and this restores the previous behaviour.
  • Loading branch information
iiroj committed Mar 30, 2020
1 parent 2cb26a6 commit 52125a9
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 213 deletions.
36 changes: 9 additions & 27 deletions lib/file.js
Expand Up @@ -4,25 +4,10 @@ const debug = require('debug')('lint-staged:file')
const fs = require('fs')
const { promisify } = require('util')

const fsAccess = promisify(fs.access)
const fsReadFile = promisify(fs.readFile)
const fsUnlink = promisify(fs.unlink)
const fsWriteFile = promisify(fs.writeFile)

/**
* Check if a file exists. Returns the filename if exists.
* @param {String} filename
* @returns {String|Boolean}
*/
const exists = async filename => {
try {
await fsAccess(filename)
return filename
} catch {
return false
}
}

/**
* Read contents of a file to buffer
* @param {String} filename
Expand All @@ -44,21 +29,19 @@ const readFile = async (filename, ignoreENOENT = true) => {
}

/**
* Unlink a file if it exists
* Remove a file
* @param {String} filename
* @param {Boolean} [ignoreENOENT=true] — Whether to throw if the file doesn't exist
*/
const unlink = async (filename, ignoreENOENT = true) => {
if (filename) {
debug('Unlinking file `%s`', filename)
try {
await fsUnlink(filename)
} catch (error) {
if (ignoreENOENT && error.code === 'ENOENT') {
debug("File `%s` doesn't exist, ignoring...", filename)
} else {
throw error
}
debug('Removing file `%s`', filename)
try {
await fsUnlink(filename)
} catch (error) {
if (ignoreENOENT && error.code === 'ENOENT') {
debug("File `%s` doesn't exist, ignoring...", filename)
} else {
throw error
}
}
}
Expand All @@ -74,7 +57,6 @@ const writeFile = async (filename, buffer) => {
}

module.exports = {
exists,
readFile,
unlink,
writeFile
Expand Down

0 comments on commit 52125a9

Please sign in to comment.