Skip to content

Commit ab457be

Browse files
authored
Merge pull request #139 from github/support-multiple-checkouts
Support checkout of multiple refs for a single repository
2 parents e05e9e6 + c562bfb commit ab457be

9 files changed

+23
-11
lines changed

lib/config-utils.test.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/external-queries.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/external-queries.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/external-queries.test.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/external-queries.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ test("API client used when reading remote config", async t => {
310310
const spyGetContents = mockGetContents(dummyResponse);
311311

312312
// Create checkout directory for remote queries repository
313-
fs.mkdirSync(path.join(tmpDir, 'foo/bar'), { recursive: true });
313+
fs.mkdirSync(path.join(tmpDir, 'foo/bar/dev'), { recursive: true });
314314

315315
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
316316
setInput('languages', 'javascript');

src/external-queries.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ setupTests(test);
1010

1111
test("checkoutExternalQueries", async t => {
1212
await util.withTmpDir(async tmpDir => {
13+
const ref = "df4c6869212341b601005567381944ed90906b6b";
1314
await externalQueries.checkoutExternalRepository(
1415
"github/codeql-go",
15-
"df4c6869212341b601005567381944ed90906b6b",
16+
ref,
1617
tmpDir);
1718

1819
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in the default branch
19-
t.true(fs.existsSync(path.join(tmpDir, "github", "codeql-go", "COPYRIGHT")));
20+
t.true(fs.existsSync(path.join(tmpDir, "github", "codeql-go", ref, "COPYRIGHT")));
2021
});
2122
});

src/external-queries.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import * as path from 'path';
99
export async function checkoutExternalRepository(repository: string, ref: string, tempDir: string): Promise<string> {
1010
core.info('Checking out ' + repository);
1111

12-
const checkoutLocation = path.join(tempDir, repository);
12+
const checkoutLocation = path.join(tempDir, repository, ref);
13+
14+
if (!checkoutLocation.startsWith(tempDir)) {
15+
// this still permits locations that mess with sibling repositories in `tempDir`, but that is acceptable
16+
throw new Error(`'${repository}@${ref}' is not a valid repository and reference.`);
17+
}
18+
1319
if (!fs.existsSync(checkoutLocation)) {
1420
const repoURL = 'https://github.com/' + repository + '.git';
1521
await exec.exec('git', ['clone', repoURL, checkoutLocation]);

0 commit comments

Comments
 (0)