Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion __test__/composal-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ test('full history, annotated tags and sparse checkout keep standard Git behavio
await expect(fs.access(path.join(workspace, 'root-file'))).rejects.toThrow()
})

test('bulk ref creation rejects invalid names without publishing local refs', async () => {
await expect(
cache({'refs/heads/main': second, 'refs/heads/invalid..name': first})
).rejects.toThrow('Local checkout cache operation failed')
})

test('dissociate makes the checkout usable after the mounted cache disappears', async () => {
const checkout = await cache()
expect(
Expand Down Expand Up @@ -271,7 +277,7 @@ test('cache fetch failure removes its alternate and allows normal GitHub fetchin

test('malformed cached ref metadata cannot write outside the temporary ref database', async () => {
await expect(
cache({'refs/heads/main\ncreate refs/heads/injected': second})
cache({[`refs/heads/main ${second}\ncreate refs/heads/injected`]: second})
).rejects.toThrow()
await expect(
fs.access(path.join(workspace, '.git', 'objects', 'info', 'alternates'))
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42327,11 +42327,13 @@ class CheckoutCache {
const refs = { ...manifest.refs, 'refs/composal/target': manifest.object_oid };
const commands = [];
for (const [name, value] of Object.entries(refs)) {
if (!oid.test(value) || !name.startsWith('refs/'))
if (!oid.test(value) ||
!name.startsWith('refs/') ||
/[\x00-\x20\x7f]/.test(name))
throw new Error('Invalid checkout cache ref');
run(['check-ref-format', name], localOrigin);
commands.push(`create ${name} ${value}`);
}
// update-ref validates the complete batch, including every ref name.
run(['update-ref', '--stdin'], localOrigin, commands.join('\n') + '\n');
const alternateFile = external_node_path_namespaceObject.join(workspace, '.git', 'objects', 'info', 'alternates');
let previous = '';
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composal-checkout",
"version": "1.0.0",
"version": "1.0.1",
"description": "Composal Git checkout action",
"type": "module",
"main": "lib/main.js",
Expand Down
8 changes: 6 additions & 2 deletions src/composal-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ export class CheckoutCache {
const refs = {...manifest.refs, 'refs/composal/target': manifest.object_oid}
const commands: string[] = []
for (const [name, value] of Object.entries(refs)) {
if (!oid.test(value) || !name.startsWith('refs/'))
if (
!oid.test(value) ||
!name.startsWith('refs/') ||
/[\x00-\x20\x7f]/.test(name)
)
throw new Error('Invalid checkout cache ref')
run(['check-ref-format', name], localOrigin)
commands.push(`create ${name} ${value}`)
}
// update-ref validates the complete batch, including every ref name.
run(['update-ref', '--stdin'], localOrigin, commands.join('\n') + '\n')
const alternateFile = path.join(
workspace,
Expand Down
Loading