From e332c806fbe6912aa2e7c89b87295f31f2af29db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Tue, 18 Jun 2019 16:00:33 +0300 Subject: [PATCH] refactor: use internal execGit in the hasPartiallyStagedFiles function (#632) --- package.json | 1 - src/gitWorkflow.js | 24 ++++++++++++++---------- yarn.lock | 32 +------------------------------- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 34681ad2b..9af40e7b3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/gitWorkflow.js b/src/gitWorkflow.js index 14f24998e..92fba9526 100644 --- a/src/gitWorkflow.js +++ b/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') @@ -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 } diff --git a/yarn.lock b/yarn.lock index 4e1466c5e..327439134 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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= @@ -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" @@ -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" @@ -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"