Skip to content

Commit

Permalink
fix: subDir detection when walking the repo content
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Jun 6, 2024
1 parent eb5a47b commit 47c4065
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions __tests__/unit/lib/adapter/GitAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/GitAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 47c4065

Please sign in to comment.