Merge pull request #4148 from n2ygk/git_ref

pass in the specified git branch ref when cloning a single branch
This commit is contained in:
Ben Lambert
2021-01-28 10:32:48 +01:00
committed by GitHub
11 changed files with 60 additions and 8 deletions
@@ -45,7 +45,7 @@ describe('AzurePreparer', () => {
metadata: {
annotations: {
[LOCATION_ANNOTATION]:
'url:https://dev.azure.com/backstage-org/backstage-project/_git/template-repo?path=%2Ftemplate.yaml',
'url:https://dev.azure.com/backstage-org/backstage-project/_git/template-repo?path=%2Ftemplate.yaml&version=GBmaster',
},
name: 'graphql-starter',
title: 'GraphQL Service',
@@ -112,6 +112,7 @@ describe('AzurePreparer', () => {
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
dir: expect.any(String),
ref: 'master',
});
});
@@ -124,6 +125,7 @@ describe('AzurePreparer', () => {
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
dir: expect.any(String),
ref: 'master',
});
});
@@ -42,6 +42,7 @@ export class AzurePreparer implements PreparerBase {
const parsedGitLocation = parseGitUrl(location);
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const ref = parsedGitLocation.ref;
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),
);
@@ -63,6 +64,7 @@ export class AzurePreparer implements PreparerBase {
await git.clone({
url: repositoryCheckoutUrl,
ref: ref,
dir: tempDir,
});
@@ -89,6 +89,7 @@ describe('BitbucketPreparer', () => {
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://bitbucket.org/backstage-project/backstage-repo',
dir: expect.any(String),
ref: expect.any(String),
});
});
@@ -113,6 +114,7 @@ describe('BitbucketPreparer', () => {
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://bitbucket.org/backstage-project/backstage-repo',
dir: expect.any(String),
ref: expect.any(String),
});
});
@@ -49,15 +49,15 @@ export class BitbucketPreparer implements PreparerBase {
const logger = opts.logger;
const templateId = template.metadata.name;
const repo = parseGitUrl(location);
const repositoryCheckoutUrl = repo.toString('https');
const parsedGitLocation = parseGitUrl(location);
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const ref = parsedGitLocation.ref;
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),
);
const templateDirectory = path.join(
`${path.dirname(repo.filepath)}`,
`${path.dirname(parsedGitLocation.filepath)}`,
template.spec.path ?? '.',
);
@@ -73,6 +73,7 @@ export class BitbucketPreparer implements PreparerBase {
await git.clone({
url: repositoryCheckoutUrl,
ref: ref,
dir: tempDir,
});
@@ -89,6 +89,7 @@ describe('GitHubPreparer', () => {
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://github.com/benjdlambert/backstage-graphql-template',
dir: expect.any(String),
ref: expect.any(String),
});
});
@@ -100,6 +101,7 @@ describe('GitHubPreparer', () => {
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://github.com/benjdlambert/backstage-graphql-template',
dir: expect.any(String),
ref: expect.any(String),
});
});
@@ -42,6 +42,7 @@ export class GithubPreparer implements PreparerBase {
const parsedGitLocation = parseGitUrl(location);
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const ref = parsedGitLocation.ref;
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),
);
@@ -63,6 +64,7 @@ export class GithubPreparer implements PreparerBase {
await git.clone({
url: repositoryCheckoutUrl,
ref: ref,
dir: tempDir,
});
@@ -87,8 +87,9 @@ describe('GitLabPreparer', () => {
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://gitlab.com/benjdlambert/backstage-graphql-template',
url: 'https://gitlab.com/benjdlambert/backstage-graphql-template.git',
dir: expect.any(String),
ref: expect.any(String),
});
});
@@ -111,8 +112,9 @@ describe('GitLabPreparer', () => {
await preparer.prepare(mockEntity, { logger: getVoidLogger() });
expect(mockGitClient.clone).toHaveBeenCalledWith({
url: 'https://gitlab.com/benjdlambert/backstage-graphql-template',
url: 'https://gitlab.com/benjdlambert/backstage-graphql-template.git',
dir: expect.any(String),
ref: expect.any(String),
});
});
@@ -41,7 +41,9 @@ export class GitlabPreparer implements PreparerBase {
const templateId = template.metadata.name;
const parsedGitLocation = parseGitUrl(location);
parsedGitLocation.git_suffix = true;
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const ref = parsedGitLocation.ref;
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),
);
@@ -61,6 +63,7 @@ export class GitlabPreparer implements PreparerBase {
await git.clone({
url: repositoryCheckoutUrl,
ref: ref,
dir: tempDir,
});