Skip to content

Commit

Permalink
feat: optimise git operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Feb 4, 2022
1 parent ac1537e commit 3ba4d8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/build-change-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { collectPackages } = require('./build-dep-graph');
const minimatch = require('minimatch');
const { getChangedReleasableFiles } = require('./releasable');
const Set = require('superset');
const path = require('path');

async function getPackageChangedFiles({
fromCommit,
Expand All @@ -31,10 +32,14 @@ async function getPackageChangedFiles({
newerCommit = fromCommit;
}

let committedChanges = await git(['diff', '--name-only', `${olderCommit}...${newerCommit}`, packageCwd], options);
let packageDir = path.relative(options.cwd, packageCwd);

let committedChanges = await git(['diff', '--name-only', `${olderCommit}...${newerCommit}`], options);
committedChanges = getLinesFromOutput(committedChanges);
let dirtyChanges = await git(['status', '--porcelain', packageCwd, '-u'], options);
committedChanges = committedChanges.filter(file => !path.relative(packageDir, file).startsWith('..'));
let dirtyChanges = await git(['status', '--porcelain', '-u'], options);
dirtyChanges = getLinesFromOutput(dirtyChanges).map(line => line.substr(3));
dirtyChanges = dirtyChanges.filter(file => !path.relative(packageDir, file).startsWith('..'));
let changedFiles = Array.from(new Set(committedChanges).union(dirtyChanges));

return changedFiles;
Expand Down
2 changes: 1 addition & 1 deletion test/build-change-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const path = require('path');
const fs = { ...require('fs'), ...require('fs').promises };

describe(buildChangeGraph, function() {
this.timeout(5e3);
// this.timeout(5e3);

// eslint-disable-next-line mocha/no-setup-in-describe
setUpSinon();
Expand Down

0 comments on commit 3ba4d8a

Please sign in to comment.