Skip to content

Commit

Permalink
Expect already-parsed URL in Git constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Apr 3, 2017
1 parent f2132be commit 8d880b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/fetchers/git-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export default class GitFetcher extends BaseFetcher {
const hash = this.hash;
invariant(hash, 'Commit hash required');

const git = new Git(this.config, this.reference, hash);
const gitUrl = Git.npmUrlToGitUrl(this.reference);
const git = new Git(this.config, gitUrl, hash);
await git.init();
await git.clone(this.dest);

Expand Down
3 changes: 2 additions & 1 deletion src/resolvers/exotics/git-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export default class GitResolver extends ExoticResolver {

const {config} = this;

const client = new Git(config, url, this.hash);
const gitUrl = Git.npmUrlToGitUrl(url);
const client = new Git(config, gitUrl, this.hash);
const commit = await client.init();

async function tryRegistry(registry): Promise<?Manifest> {
Expand Down
8 changes: 5 additions & 3 deletions src/resolvers/exotics/hosted-git-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export default class HostedGitResolver extends ExoticResolver {
}

async getRefOverHTTP(url: string): Promise<string> {
const client = new Git(this.config, url, this.hash);
const gitUrl = Git.npmUrlToGitUrl(url);
const client = new Git(this.config, gitUrl, this.hash);

let out = await this.config.requestManager.request({
url: `${url}/info/refs?service=git-upload-pack`,
Expand Down Expand Up @@ -211,8 +212,9 @@ 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(Git.npmUrlToGitUrl(sshUrl))) {
const archiveClient = new Git(this.config, sshUrl, this.hash);
const sshGitUrl = Git.npmUrlToGitUrl(sshUrl);
if (await Git.hasArchiveCapability(sshGitUrl)) {
const archiveClient = new Git(this.config, sshGitUrl, this.hash);
const commit = await archiveClient.init();
return await this.fork(GitResolver, true, `${sshUrl}#${commit}`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const supportsArchiveCache: { [key: string]: boolean } = map({
});

export default class Git {
constructor(config: Config, url: string, hash: string) {
constructor(config: Config, gitUrl: GitUrl, hash: string) {
this.supportsArchive = false;
this.fetched = false;
this.config = config;
this.reporter = config.reporter;
this.hash = hash;
this.ref = hash;
this.gitUrl = Git.npmUrlToGitUrl(url);
this.gitUrl = gitUrl;
this.cwd = this.config.getTemp(crypto.hash(this.gitUrl.repository));
}

Expand Down

0 comments on commit 8d880b1

Please sign in to comment.