From c4870b6a39f10c6026e68bebdcaa3096bdbb7721 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 22 Jun 2026 17:54:38 +0200 Subject: [PATCH] Fix change dection for checkHeaders script --- dev-packages/cli/src/commands/check-header.ts | 10 +++-- .../cli/tests/e2e/check-header.e2e.spec.ts | 37 +++++++++++++++++-- dev-packages/cli/tests/helpers/git-helper.ts | 7 +++- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/dev-packages/cli/src/commands/check-header.ts b/dev-packages/cli/src/commands/check-header.ts index 38bffc1..51c203e 100644 --- a/dev-packages/cli/src/commands/check-header.ts +++ b/dev-packages/cli/src/commands/check-header.ts @@ -112,13 +112,15 @@ async function getFiles(rootDir: string, options: HeaderCheckOptions): Promise convert + let relativeFiles = changedFiles.map(file => path.relative(rootDir, file)).filter(minimatch.filter(includePattern)); excludePattern.forEach(pattern => { - changedFiles = changedFiles.filter(minimatch.filter(`!${pattern}`)); + relativeFiles = relativeFiles.filter(minimatch.filter(`!${pattern}`)); }); - const result = changedFiles.filter(file => fs.existsSync(file)); + const result = relativeFiles.filter(file => fs.existsSync(path.resolve(rootDir, file))); return resolveFiles(result); } diff --git a/dev-packages/cli/tests/e2e/check-header.e2e.spec.ts b/dev-packages/cli/tests/e2e/check-header.e2e.spec.ts index efed5ab..7e464d5 100644 --- a/dev-packages/cli/tests/e2e/check-header.e2e.spec.ts +++ b/dev-packages/cli/tests/e2e/check-header.e2e.spec.ts @@ -14,13 +14,13 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { describe, it, beforeEach, afterEach, expect } from 'vitest'; import { execSync } from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { runCli } from '../helpers/cli-helper'; -import { commitFile, createTempGitRepo } from '../helpers/git-helper'; -import { cleanupTempDir } from '../helpers/test-helper'; +import { commitFile, createTempGitRepo, initGitRepo } from '../helpers/git-helper'; +import { cleanupTempDir, createTempDir } from '../helpers/test-helper'; const VALID_HEADER = `/******************************************************************************** * Copyright (c) ${new Date().getFullYear()} EclipseSource and others. @@ -108,6 +108,37 @@ describe('checkHeaders e2e', () => { expect(result.stdout).to.contain('Check copy right headers of 1 files'); }); + describe('with a repository under a dot-directory', () => { + let hiddenRepoDir: string; + let hiddenRoot: string; + + beforeEach(() => { + hiddenRoot = createTempDir(); + hiddenRepoDir = initGitRepo(path.join(hiddenRoot, '.hidden', 'repo')); + }); + + afterEach(() => { + cleanupTempDir(hiddenRoot); + }); + + it('should still detect changed files with --type changes', () => { + commitFile(hiddenRepoDir, 'src/base.ts', VALID_HEADER + '\nconst x = 1;\n', 'add base file'); + execSync('git checkout -b feature', { cwd: hiddenRepoDir }); + commitFile(hiddenRepoDir, 'src/feature.ts', 'const y = 2;\n', 'add feature file'); + const result = runCli(['checkHeaders', hiddenRepoDir, '--type', 'changes']); + expect(result.stdout).to.contain('Check copy right headers of 1 files'); + expect(result.stdout).to.contain('feature.ts'); + expect(result.stdout).to.not.contain('base.ts'); + }); + + it('should still detect changed files with --type lastCommit', () => { + commitFile(hiddenRepoDir, 'src/old.ts', VALID_HEADER + '\nconst x = 1;\n', 'add old file'); + commitFile(hiddenRepoDir, 'src/new.ts', 'const y = 2;\n', 'add new file'); + const result = runCli(['checkHeaders', hiddenRepoDir, '--type', 'lastCommit']); + expect(result.stdout).to.contain('Check copy right headers of 1 files'); + }); + }); + it('should check custom file extensions with --fileExtensions', () => { commitFile(repoDir, 'src/script.js', 'const x = 1;\n', 'add js file'); commitFile(repoDir, 'src/good.ts', VALID_HEADER + '\nconst y = 2;\n', 'add ts file'); diff --git a/dev-packages/cli/tests/helpers/git-helper.ts b/dev-packages/cli/tests/helpers/git-helper.ts index 740df48..b46659d 100644 --- a/dev-packages/cli/tests/helpers/git-helper.ts +++ b/dev-packages/cli/tests/helpers/git-helper.ts @@ -25,7 +25,12 @@ function git(args: string, cwd: string): string { /** Creates a temporary git repository with an initial commit. */ export function createTempGitRepo(): string { - const dir = createTempDir(); + return initGitRepo(createTempDir()); +} + +/** Initializes a git repository with an initial commit at the given directory (created if missing). */ +export function initGitRepo(dir: string): string { + fs.mkdirSync(dir, { recursive: true }); git('init', dir); git('config user.email "test@test.com"', dir); git('config user.name "Test"', dir);