Skip to content

Commit

Permalink
refactor: use internal execGit in the hasPartiallyStagedFiles function (
Browse files Browse the repository at this point in the history
  • Loading branch information
Iiro Jäppinen authored and okonet committed Jun 18, 2019
1 parent 7286f02 commit e332c80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -33,7 +33,6 @@
"dedent": "^0.7.0",
"del": "^3.0.0",
"execa": "^1.0.0",
"g-status": "^2.0.2",
"is-glob": "^4.0.0",
"is-windows": "^1.0.2",
"listr": "^0.14.2",
Expand Down
24 changes: 14 additions & 10 deletions src/gitWorkflow.js
@@ -1,6 +1,5 @@
'use strict'

const gStatus = require('g-status')
const del = require('del')
const debug = require('debug')('lint-staged:git')

Expand Down Expand Up @@ -32,15 +31,20 @@ async function getDiffForTrees(tree1, tree2, options) {
}

async function hasPartiallyStagedFiles(options) {
const { cwd } = options
const files = await gStatus({ cwd })
const partiallyStaged = files.filter(
file =>
file.index !== ' ' &&
file.workingTree !== ' ' &&
file.index !== '?' &&
file.workingTree !== '?'
)
const stdout = await execGit(['status', '--porcelain'], options)
if (!stdout) return false

const changedFiles = stdout.split('\n')
const partiallyStaged = changedFiles.filter(line => {
/**
* See https://git-scm.com/docs/git-status#_short_format
* The first letter of the line represents current index status,
* and second the working tree
*/
const [index, workingTree] = line
return index !== ' ' && workingTree !== ' ' && index !== '?' && workingTree !== '?'
})

return partiallyStaged.length > 0
}

Expand Down
32 changes: 1 addition & 31 deletions yarn.lock
Expand Up @@ -1392,13 +1392,6 @@ debug@^3.1.0, debug@^3.2.6:
dependencies:
ms "^2.1.1"

debug@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
dependencies:
ms "^2.1.1"

decamelize@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
Expand Down Expand Up @@ -1603,7 +1596,7 @@ es-to-primitive@^1.2.0:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^1.0.5:
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
Expand Down Expand Up @@ -2227,15 +2220,6 @@ functional-red-black-tree@^1.0.1:
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=

g-status@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/g-status/-/g-status-2.0.2.tgz#270fd32119e8fc9496f066fe5fe88e0a6bc78b97"
integrity sha512-kQoE9qH+T1AHKgSSD0Hkv98bobE90ILQcXAF4wvGgsr7uFqNvwmh8j+Lq3l0RVt3E3HjSbv2B9biEGcEtpHLCA==
dependencies:
arrify "^1.0.1"
matcher "^1.0.0"
simple-git "^1.85.0"

gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
Expand Down Expand Up @@ -3745,13 +3729,6 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

matcher@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/matcher/-/matcher-1.1.1.tgz#51d8301e138f840982b338b116bb0c09af62c1c2"
integrity sha512-+BmqxWIubKTRKNWx/ahnCkk3mG8m7OturVlqq6HiojGJTd5hVYbgZm6WzcYPCoB+KBT4Vd6R7WSRG2OADNaCjg==
dependencies:
escape-string-regexp "^1.0.4"

math-random@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.4.tgz#5dd6943c938548267016d4e34f057583080c514c"
Expand Down Expand Up @@ -5003,13 +4980,6 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=

simple-git@^1.85.0:
version "1.113.0"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.113.0.tgz#668989728a1e9cf4ec6c72b69ea2eecc93489bea"
integrity sha512-i9WVsrK2u0G/cASI9nh7voxOk9mhanWY9eGtWBDSYql6m49Yk5/Fan6uZsDr/xmzv8n+eQ8ahKCoEr8cvU3h+g==
dependencies:
debug "^4.0.1"

sisteransi@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce"
Expand Down

0 comments on commit e332c80

Please sign in to comment.