-
-
Notifications
You must be signed in to change notification settings - Fork 749
fix: improve generated git cache key #3839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+108
β7
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { defineGitSource } from '../../src/utils/source' | ||
|
|
||
| vi.mock('../../src/utils/git', () => ({ | ||
| downloadGitRepository: vi.fn(), | ||
| })) | ||
|
|
||
| async function resolveCwd(repository: string | Record<string, unknown>) { | ||
| const source = defineGitSource({ include: 'docs/**', repository } as never) | ||
| await source.prepare!({ rootDir: '/root' } as never) | ||
| return source.cwd | ||
| } | ||
|
|
||
| describe('defineGitSource', () => { | ||
| it('keys the checkout directory on the resolved ref', async () => { | ||
| expect(await resolveCwd('https://github.com/nuxt/cli/tree/main')) | ||
| .toBe('/root/.data/content/github.com-nuxt-cli-main') | ||
| expect(await resolveCwd({ url: 'https://github.com/nuxt/cli', tag: 'v3.37.0' })) | ||
| .toBe('/root/.data/content/github.com-nuxt-cli-tag-v3.37.0') | ||
| expect(await resolveCwd({ url: 'https://github.com/nuxt/cli', branch: 'dev' })) | ||
| .toBe('/root/.data/content/github.com-nuxt-cli-dev') | ||
| }) | ||
|
|
||
| it('distinguishes a branch from a tag of the same name', async () => { | ||
| const branch = await resolveCwd({ url: 'https://github.com/nuxt/cli', branch: 'v3.37.0' }) | ||
| const tag = await resolveCwd({ url: 'https://github.com/nuxt/cli', tag: 'v3.37.0' }) | ||
| expect(branch).not.toBe(tag) | ||
| }) | ||
|
|
||
| it('sanitises slashes in the ref without collapsing distinct refs', async () => { | ||
| const slashed = await resolveCwd({ url: 'https://github.com/nuxt/cli', branch: 'release/v4.0.0' }) | ||
| const dashed = await resolveCwd({ url: 'https://github.com/nuxt/cli', branch: 'release-v4.0.0' }) | ||
|
|
||
| expect(slashed).toMatch(/^\/root\/\.data\/content\/github\.com-nuxt-cli-release-v4\.0\.0-/) | ||
| expect(dashed).toBe('/root/.data/content/github.com-nuxt-cli-release-v4.0.0') | ||
| expect(slashed).not.toBe(dashed) | ||
|
|
||
| const escaped = await resolveCwd({ url: 'https://github.com/nuxt/cli', branch: '../../escape' }) | ||
| expect(escaped.split('/').slice(0, -1).join('/')).toBe('/root/.data/content') | ||
| }) | ||
|
|
||
| it('defaults to main when no ref is given', async () => { | ||
| expect(await resolveCwd('https://github.com/nuxt/cli')) | ||
| .toBe('/root/.data/content/github.com-nuxt-cli-main') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { describe, expect, test, vi } from 'vitest' | ||
|
|
||
| vi.mock('isomorphic-git', () => ({ | ||
| default: { | ||
| getRemoteInfo: vi.fn(async () => ({ | ||
| HEAD: 'refs/heads/main', | ||
| refs: { | ||
| heads: { | ||
| main: 'aaa', | ||
| release: { 'v4.0.0': 'bbb' }, | ||
| }, | ||
| tags: { | ||
| 'v1.0': { beta: 'ccc' }, | ||
| }, | ||
| }, | ||
| })), | ||
| }, | ||
| })) | ||
|
|
||
| const { getGitRemoteHash } = await import('../../../src/utils/git') | ||
|
|
||
| describe('getGitRemoteHash with nested refs', () => { | ||
| test('resolves a branch name containing a slash', async () => { | ||
| const url = 'https://github.com/nuxt/content' | ||
| const ref = { branch: 'release/v4.0.0' } | ||
|
|
||
| expect(await getGitRemoteHash(url, ref)).toBe('bbb') | ||
| expect(await getGitRemoteHash(url, ref)).toBe('bbb') | ||
| }) | ||
|
|
||
| test('resolves a tag name containing a slash', async () => { | ||
| expect(await getGitRemoteHash('https://github.com/nuxt/content', { tag: 'v1.0/beta' })).toBe('ccc') | ||
| }) | ||
|
|
||
| test('does not return an object for a partial ref', async () => { | ||
| expect(await getGitRemoteHash('https://github.com/nuxt/content', { branch: 'release' })).toBeUndefined() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.