Skip to content

Commit

Permalink
Fix support for private git url. Fix yarnpkg#573
Browse files Browse the repository at this point in the history
  • Loading branch information
ramasilveyra committed Oct 14, 2016
1 parent dc18f27 commit 0b9d1b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/resolvers/exotics/bitbucket-resolver.js
Expand Up @@ -16,6 +16,10 @@ export default class BitbucketResolver extends HostedGitResolver {
}

static getGitSSHUrl(parts: ExplodedFragment): string {
return `git+ssh://git@bitbucket.org/${ parts.user }/${ parts.repo }.git`;
}

static getGitSSH(parts: ExplodedFragment): string {
return `git@bitbucket.org:${parts.user}/${parts.repo}.git`;
}

Expand Down
4 changes: 4 additions & 0 deletions src/resolvers/exotics/github-resolver.js
Expand Up @@ -26,6 +26,10 @@ export default class GitHubResolver extends HostedGitResolver {
}

static getGitSSHUrl(parts: ExplodedFragment): string {
return `git+ssh://git@github.com/${ parts.user }/${ parts.repo }.git`;
}

static getGitSSH(parts: ExplodedFragment): string {
return `git@github.com:${parts.user}/${parts.repo}.git`;
}

Expand Down
4 changes: 4 additions & 0 deletions src/resolvers/exotics/gitlab-resolver.js
Expand Up @@ -16,6 +16,10 @@ export default class GitLabResolver extends HostedGitResolver {
}

static getGitSSHUrl(parts: ExplodedFragment): string {
return `git+ssh://git@gitlab.com/${ parts.user }/${ parts.repo }.git`;
}

static getGitSSH(parts: ExplodedFragment): string {
return `git@gitlab.com:${parts.user}/${parts.repo}.git`;
}

Expand Down
22 changes: 14 additions & 8 deletions src/resolvers/exotics/hosted-git-resolver.js
Expand Up @@ -71,6 +71,11 @@ export default class HostedGitResolver extends ExoticResolver {
throw new Error('Not implemented');
}

static getGitSSH(exploded: ExplodedFragment): string {
exploded;
throw new Error('Not implemented');
}

static getHTTPFileUrl(exploded: ExplodedFragment, filename: string, commit: string) {
exploded;
filename;
Expand Down Expand Up @@ -167,14 +172,15 @@ export default class HostedGitResolver extends ExoticResolver {
}

async resolve(): Promise<Manifest> {
const httpUrl = this.constructor.getGitHTTPUrl(this.exploded);
const sshUrl = this.constructor.getGitSSHUrl(this.exploded);
const gitHTTPUrl = this.constructor.getGitHTTPUrl(this.exploded);
const gitSSHUrl = this.constructor.getGitSSHUrl(this.exploded);
const gitSSH = this.constructor.getGitSSH(this.exploded);

// If we can access the files over HTTP then we should as it's MUCH faster than git
// archive and tarball unarchiving. The HTTP API is only available for public repos
// though.
if (await this.hasHTTPCapability(httpUrl)) {
return await this.resolveOverHTTP(httpUrl);
if (await this.hasHTTPCapability(gitHTTPUrl)) {
return await this.resolveOverHTTP(gitHTTPUrl);
}

// If the url is accessible over git archive then we should immediately delegate to
Expand All @@ -183,13 +189,13 @@ export default class HostedGitResolver extends ExoticResolver {
// NOTE: Here we use a different url than when we delegate to the git resolver later on.
// This is because `git archive` requires access over ssh and github only allows that
// if you have write permissions
if (await Git.hasArchiveCapability(sshUrl)) {
const archiveClient = new Git(this.config, sshUrl, this.hash);
if (await Git.hasArchiveCapability(gitSSH)) {
const archiveClient = new Git(this.config, gitSSH, this.hash);
const commit = await archiveClient.initRemote();
return await this.fork(GitResolver, true, `${sshUrl}#${commit}`);
return await this.fork(GitResolver, true, `${gitSSH}#${commit}`);
}

// fallback to the plain git resolver
return await this.fork(GitResolver, true, sshUrl);
return await this.fork(GitResolver, true, gitSSHUrl);
}
}

0 comments on commit 0b9d1b5

Please sign in to comment.