Skip to content

Commit

Permalink
Properly propagate hash revisions of certain git urls + no longer ass…
Browse files Browse the repository at this point in the history
…ume the default branch is master
  • Loading branch information
svanderburg committed Sep 7, 2016
1 parent a087122 commit 7e0221b
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 72 deletions.
62 changes: 38 additions & 24 deletions lib/packagefetcher/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
break;
}

var commitIsh = parsedUrl.hash;
if(commitIsh === null) // Use master as default commitish
commitIsh = "master";
else
commitIsh = commitIsh.substr(1);
/* Compose the commitIsh out of the hash suffix, if applicable */
var commitIsh;

if(parsedUrl.hash !== null) {
commitIsh = parsedUrl.hash.substr(1);
} else {
commitIsh = null;
}

delete parsedUrl.hash;

Expand Down Expand Up @@ -107,11 +110,18 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
},

function(callback) {
var branch;

process.stderr.write("Parsing the revision of commitish: "+commitIsh+"\n");
if(commitIsh === null) {
branch = "HEAD";
} else {
branch = commitIsh;
}

process.stderr.write("Parsing the revision of commitish: "+branch+"\n");

/* Check whether the given commitish corresponds to a hash */
var gitRevParse = child_process.spawn("git", [ "rev-parse", commitIsh ], {
var gitRevParse = child_process.spawn("git", [ "rev-parse", branch ], {
cwd: repositoryDir
});

Expand All @@ -130,7 +140,7 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
},

function(callback) {
if(rev == "") {
if(commitIsh !== null && rev == "") {
process.stderr.write("Parsing the revision of commitish: origin/"+commitIsh+"\n");

/* Resolve the hash of the branch/tag */
Expand All @@ -156,22 +166,26 @@ function fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback) {
},

function(callback) {
rev = rev.substr(0, rev.length - 1);

process.stderr.write("Checking out revision: "+rev+"\n");

/* Check out the corresponding revision */
var gitCheckout = child_process.spawn("git", [ "checkout", rev ], {
cwd: repositoryDir,
stdio: "inherit"
});

gitCheckout.on("close", function(code) {
if(code == 0)
callback(null);
else
callback("git checkout exited with status: "+code);
});
if(rev == "") {
callback(null);
} else {
rev = rev.substr(0, rev.length - 1);

process.stderr.write("Checking out revision: "+rev+"\n");

/* Check out the corresponding revision */
var gitCheckout = child_process.spawn("git", [ "checkout", rev ], {
cwd: repositoryDir,
stdio: "inherit"
});

gitCheckout.on("close", function(code) {
if(code == 0)
callback(null);
else
callback("git checkout exited with status: "+code);
});
}
},

function(callback) {
Expand Down
19 changes: 15 additions & 4 deletions lib/packageset.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function PackageSet(registryURL, outputDir) {
this.sources = {};
}

function composeGitURL(baseURL, parsedUrl) {
var hashComponent;

if(parsedUrl.hash === null)
hashComponent = "";
else
hashComponent = parsedUrl.hash;

return baseURL + "/" + parsedUrl.host + parsedUrl.path + hashComponent;
}

/**
* Fetches package metadata from an external source that is determined by the
* version specifier, so that a partial Nix expression can be generated that
Expand All @@ -55,13 +66,13 @@ PackageSet.prototype.fetchMetaData = function(baseDir, dependencyName, versionSp
if(parsedVersionSpec !== null) { // If the version is valid semver range, fetch the package from the NPM registry
fetchMetaDataFromNPMRegistry(baseDir, dependencyName, parsedVersionSpec, this.registryURL, callback);
} else if(parsedUrl.protocol == "github:") { // If the version is a GitHub repository, compose the corresponding Git URL and do a Git checkout
fetchMetaDataFromGit(baseDir, dependencyName, "git://github.com/"+parsedUrl.host+parsedUrl.path, callback);
fetchMetaDataFromGit(baseDir, dependencyName, composeGitURL("git://github.com", parsedUrl), callback);
} else if(parsedUrl.protocol == "gist:") { // If the version is a GitHub gist repository, compose the corresponding Git URL and do a Git checkout
fetchMetaDataFromGit(baseDir, dependencyName, "https://gist.github.com/"+parsedUrl.host+parsedUrl.path, callback);
fetchMetaDataFromGit(baseDir, dependencyName, composeGitURL("https://gist.github.com", parsedUrl), callback);
} else if(parsedUrl.protocol == "bitbucket:") { // If the version is a Bitbucket repository, compose the corresponding Git URL and do a Git checkout
fetchMetaDataFromGit(baseDir, dependencyName, "git://bitbucket.org/"+parsedUrl.host+parsedUrl.path, callback);
fetchMetaDataFromGit(baseDir, dependencyName, composeGitURL("git://bitbucket.org", parsedUrl), callback);
} else if(parsedUrl.protocol == "gitlab:") { // If the version is a Gitlab repository, compose the corresponding Git URL and do a Git checkout
fetchMetaDataFromGit(baseDir, dependencyName, "git://gitlab.com/"+parsedUrl.host+parsedUrl.path, callback);
fetchMetaDataFromGit(baseDir, dependencyName, composeGitURL("git://gitlab.com", parsedUrl), callback);
} else if(typeof parsedUrl.protocol == "string" && parsedUrl.protocol.substr(0, 3) == "git") { // If the version is a Git URL do a Git checkout
fetchMetaDataFromGit(baseDir, dependencyName, versionSpec, callback);
} else if(parsedUrl.protocol == "http:" || parsedUrl.protocol == "https:") { // If the version is an HTTP URL do a download
Expand Down
20 changes: 10 additions & 10 deletions node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ let
sha1 = "2d46fa874337af9498a2f12bb43d8d0be4a36873";
};
};
"inherits-2.0.1" = {
"inherits-2.0.2" = {
name = "inherits";
packageName = "inherits";
version = "2.0.1";
version = "2.0.2";
src = fetchurl {
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz";
sha1 = "b17d08d326b4423e568eff719f91b0b1cbdf69f1";
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.2.tgz";
sha1 = "7880e686ae72d327c3e7cdb406c3b71ad12b36b8";
};
};
"typedarray-0.0.6" = {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ let
sources."chownr-1.0.1"
(sources."concat-stream-1.5.2" // {
dependencies = [
sources."inherits-2.0.1"
sources."inherits-2.0.2"
sources."typedarray-0.0.6"
(sources."readable-stream-2.0.6" // {
dependencies = [
Expand Down Expand Up @@ -1409,7 +1409,7 @@ let
(sources."readable-stream-2.0.6" // {
dependencies = [
sources."core-util-is-1.0.2"
sources."inherits-2.0.1"
sources."inherits-2.0.2"
sources."isarray-1.0.0"
sources."process-nextick-args-1.0.7"
sources."string_decoder-0.10.31"
Expand Down Expand Up @@ -1542,7 +1542,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
(sources."minimatch-3.0.3" // {
dependencies = [
(sources."brace-expansion-1.1.6" // {
Expand All @@ -1568,7 +1568,7 @@ let
dependencies = [
sources."buffer-shims-1.0.0"
sources."core-util-is-1.0.2"
sources."inherits-2.0.1"
sources."inherits-2.0.2"
sources."isarray-1.0.0"
sources."process-nextick-args-1.0.7"
sources."string_decoder-0.10.31"
Expand Down Expand Up @@ -1619,7 +1619,7 @@ let
sources."proto-list-1.2.4"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
sources."ini-1.3.4"
(sources."mkdirp-0.5.1" // {
dependencies = [
Expand Down Expand Up @@ -1689,7 +1689,7 @@ let
})
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
];
})
(sources."temp-0.8.3" // {
Expand Down
7 changes: 1 addition & 6 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ rec {
in
map (name: builtins.getAttr name tests_) (builtins.attrNames tests_)
) systems)
++ pkgs.lib.flatten (map (system:
let
tests_ = tests."${system}".grunt;
in
map (name: builtins.getAttr name tests_) (builtins.attrNames tests_)
) systems);
++ map (system: tests."${system}".grunt) systems;
};
}
20 changes: 10 additions & 10 deletions tests/grunt/node-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,13 @@ let
sha1 = "db3204cd5a9de2e6cd890b85c6e2f66bcf4f620a";
};
};
"inherits-2.0.1" = {
"inherits-2.0.2" = {
name = "inherits";
packageName = "inherits";
version = "2.0.1";
version = "2.0.2";
src = fetchurl {
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz";
sha1 = "b17d08d326b4423e568eff719f91b0b1cbdf69f1";
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.2.tgz";
sha1 = "7880e686ae72d327c3e7cdb406c3b71ad12b36b8";
};
};
"once-1.4.0" = {
Expand Down Expand Up @@ -1407,7 +1407,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand All @@ -1425,7 +1425,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand Down Expand Up @@ -1545,7 +1545,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand Down Expand Up @@ -1581,7 +1581,7 @@ let
sources."core-util-is-1.0.2"
sources."isarray-0.0.1"
sources."string_decoder-0.10.31"
sources."inherits-2.0.1"
sources."inherits-2.0.2"
];
})
sources."entities-1.0.0"
Expand Down Expand Up @@ -1619,7 +1619,7 @@ let
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
(sources."once-1.4.0" // {
dependencies = [
sources."wrappy-1.0.2"
Expand Down Expand Up @@ -1653,7 +1653,7 @@ let
sources."depd-1.1.0"
(sources."http-errors-1.3.1" // {
dependencies = [
sources."inherits-2.0.1"
sources."inherits-2.0.2"
sources."statuses-1.3.0"
];
})
Expand Down
10 changes: 5 additions & 5 deletions tests/grunt/supplement.nix
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,13 @@ let
sha1 = "db3204cd5a9de2e6cd890b85c6e2f66bcf4f620a";
};
};
"inherits-2.0.1" = {
"inherits-2.0.2" = {
name = "inherits";
packageName = "inherits";
version = "2.0.1";
version = "2.0.2";
src = fetchurl {
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz";
sha1 = "b17d08d326b4423e568eff719f91b0b1cbdf69f1";
url = "https://registry.npmjs.org/inherits/-/inherits-2.0.2.tgz";
sha1 = "7880e686ae72d327c3e7cdb406c3b71ad12b36b8";
};
};
"once-1.4.0" = {
Expand Down Expand Up @@ -1285,7 +1285,7 @@ in
sources."wrappy-1.0.2"
];
})
sources."inherits-2.0.1"
sources."inherits-2.0.2"
(sources."minimatch-3.0.3" // {
dependencies = [
(sources."brace-expansion-1.1.6" // {
Expand Down
Loading

0 comments on commit 7e0221b

Please sign in to comment.