From bfa36c60873e3ffabedf45184ae74af0df566de6 Mon Sep 17 00:00:00 2001 From: Paul Hatcherian <1835615+PaulHatch@users.noreply.github.com> Date: Sat, 5 Sep 2020 08:39:02 -0400 Subject: [PATCH] Fix change tracking when no previous tag exists --- dist/index.js | 9 +++++++-- index.js | 9 +++++++-- index.test.js | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index f5e8f04..549e18d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1091,8 +1091,13 @@ async function run() { const log = await cmd(logCommand); if (changePath !== '') { - const changedFiles = await cmd(`git diff --name-only ${(root === '' ? branch : `${root}..${branch}`)} -- ${changePath}`); - changed = changedFiles.length > 0; + if (root === '') { + const changedFiles = await cmd(`git log --name-only --oneline ${branch} -- ${changePath}`); + changed = changedFiles.length > 0; + } else { + const changedFiles = await cmd(`git diff --name-only ${root}..${branch} -- ${changePath}`); + changed = changedFiles.length > 0; + } } let history = log diff --git a/index.js b/index.js index 202db2f..29a6684 100644 --- a/index.js +++ b/index.js @@ -145,8 +145,13 @@ async function run() { const log = await cmd(logCommand); if (changePath !== '') { - const changedFiles = await cmd(`git diff --name-only ${(root === '' ? branch : `${root}..${branch}`)} -- ${changePath}`); - changed = changedFiles.length > 0; + if (root === '') { + const changedFiles = await cmd(`git log --name-only --oneline ${branch} -- ${changePath}`); + changed = changedFiles.length > 0; + } else { + const changedFiles = await cmd(`git diff --name-only ${root}..${branch} -- ${changePath}`); + changed = changedFiles.length > 0; + } } let history = log diff --git a/index.test.js b/index.test.js index e85f9cf..c596113 100644 --- a/index.test.js +++ b/index.test.js @@ -331,6 +331,19 @@ test('Changes to monitored path is false when changes are not in path', () => { repo.clean(); }); +test('Changes can be detected without tags', () => { + const repo = createTestRepo({ tag_prefix: '' }); // 0.0.0 + + repo.makeCommit('Initial Commit'); // 0.0.1 + repo.exec('mkdir project1'); + repo.makeCommit(`Second Commit`, 'project1'); // 0.0.2 + const result = repo.runAction({ change_path: "project1" }); + + expect(result).toMatch('::set-output name=changed::true'); + + repo.clean(); +}); + test('Changes to multiple monitored path is true when change is in path', () => { const repo = createTestRepo({ tag_prefix: '' }); // 0.0.0 @@ -339,7 +352,7 @@ test('Changes to multiple monitored path is true when change is in path', () => repo.exec('mkdir project1'); repo.exec('mkdir project2'); repo.makeCommit(`Second Commit`, 'project2'); // 0.0.2 - const result = repo.runAction({ change_path: "./project1 ./project2" }); + const result = repo.runAction({ change_path: "project1 project2" }); expect(result).toMatch('::set-output name=changed::true');