From 47c4065dda4f9616e781ff54e1a18164d2a5cf4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Colladon?= Date: Thu, 6 Jun 2024 17:44:46 +0200 Subject: [PATCH] fix: subDir detection when walking the repo content --- __tests__/unit/lib/adapter/GitAdapter.test.ts | 23 +++++++++++++++++++ src/adapter/GitAdapter.ts | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/__tests__/unit/lib/adapter/GitAdapter.test.ts b/__tests__/unit/lib/adapter/GitAdapter.test.ts index 1c75b761..bff334ae 100644 --- a/__tests__/unit/lib/adapter/GitAdapter.test.ts +++ b/__tests__/unit/lib/adapter/GitAdapter.test.ts @@ -667,6 +667,29 @@ describe('GitAdapter', () => { }) describe('when filepath should be treated', () => { + describe(`when "config.source" is '.'`, () => { + it('returns the normalized path', async () => { + // Arrange + const firstEntry = { + type: jest.fn(() => Promise.resolve('blob')), + oid: jest.fn(() => undefined), + } as unknown as WalkerEntry + const secondEntry = { + type: jest.fn(() => Promise.resolve('blob')), + oid: jest.fn(() => 10), + } as unknown as WalkerEntry + + // Act + const result = await diffLineWalker({ + ...config, + source: '.', + })('force-app/test.file', [firstEntry, secondEntry]) + + // Assert + expect(result).toBe('A\tforce-app/test.file') + }) + }) + describe(`when filepath starts with "config.source"`, () => { it('returns the normalized path', async () => { // Arrange diff --git a/src/adapter/GitAdapter.ts b/src/adapter/GitAdapter.ts index 42a61957..8e0d0a88 100644 --- a/src/adapter/GitAdapter.ts +++ b/src/adapter/GitAdapter.ts @@ -16,7 +16,7 @@ import { import type { Config } from '../types/config' import type { FileGitRef } from '../types/git' import { SOURCE_DEFAULT_VALUE } from '../utils/cliConstants' -import { dirExists, fileExists, treatPathSep } from '../utils/fsUtils' +import { dirExists, fileExists, isSubDir, treatPathSep } from '../utils/fsUtils' import { getLFSObjectContentPath, isLFS } from '../utils/gitLfsHelper' const firstCommitParams = ['rev-list', '--max-parents=0', 'HEAD'] @@ -293,7 +293,7 @@ const pathDoesNotStartsWith = (root: string) => { return (path: string) => gitFormattedRoot !== SOURCE_DEFAULT_VALUE && - !path.startsWith(gitFormattedRoot) + !isSubDir(gitFormattedRoot, path) } const evaluateShouldSkip = (base: string) => {