Fix change tracking when no previous tag exists

This commit is contained in:
Paul Hatcherian 2020-09-05 08:39:02 -04:00
parent e7dede1b52
commit bfa36c6087
3 changed files with 28 additions and 5 deletions

9
dist/index.js vendored
View file

@ -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

View file

@ -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

View file

@ -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');