summaryrefslogtreecommitdiffstats
path: root/lib/utils/git.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/git.js')
-rw-r--r--lib/utils/git.js130
1 files changed, 65 insertions, 65 deletions
diff --git a/lib/utils/git.js b/lib/utils/git.js
index 9a669db..2c3dd3f 100644
--- a/lib/utils/git.js
+++ b/lib/utils/git.js
@@ -15,7 +15,7 @@ var GIT_TMP = null;
// Check if an url is a git dependency url
function checkGitUrl(giturl) {
- return (giturl.indexOf(GIT_PREFIX) === 0);
+ return (giturl.indexOf(GIT_PREFIX) === 0);
}
// Validates a SHA in hexadecimal
@@ -25,88 +25,88 @@ function validateSha(str) {
// Parse and extract infos
function parseGitUrl(giturl) {
- var ref, uri, fileParts, filepath;
+ var ref, uri, fileParts, filepath;
- if (!checkGitUrl(giturl)) return null;
- giturl = giturl.slice(GIT_PREFIX.length);
+ if (!checkGitUrl(giturl)) return null;
+ giturl = giturl.slice(GIT_PREFIX.length);
- uri = new URI(giturl);
- ref = uri.fragment() || "master";
- uri.fragment(null);
+ uri = new URI(giturl);
+ ref = uri.fragment() || "master";
+ uri.fragment(null);
- // Extract file inside the repo (after the .git)
- fileParts =uri.path().split(".git");
- filepath = fileParts.length > 1? fileParts.slice(1).join(".git") : "";
- if (filepath[0] == "/") filepath = filepath.slice(1);
+ // Extract file inside the repo (after the .git)
+ fileParts =uri.path().split(".git");
+ filepath = fileParts.length > 1? fileParts.slice(1).join(".git") : "";
+ if (filepath[0] == "/") filepath = filepath.slice(1);
- // Recreate pathname without the real filename
- uri.path(_.first(fileParts)+".git");
+ // Recreate pathname without the real filename
+ uri.path(_.first(fileParts)+".git");
- return {
- host: uri.toString(),
- ref: ref || "master",
- filepath: filepath
- };
+ return {
+ host: uri.toString(),
+ ref: ref || "master",
+ filepath: filepath
+ };
}
// Clone a git repo from a specific ref
function cloneGitRepo(host, ref) {
- var isBranch = false;
-
- ref = ref || "master";
- if (!validateSha(ref)) isBranch = true;
-
- return Q()
-
- // Create temporary folder to store git repos
- .then(function() {
- if (GIT_TMP) return;
- return fs.tmp.dir()
- .then(function(_tmp) {
- GIT_TMP = _tmp;
- });
- })
-
- // Return or clone the git repo
- .then(function() {
- // Unique ID for repo/ref combinaison
- var repoId = crc.crc32(host+"#"+ref).toString(16);
-
- // Absolute path to the folder
- var repoPath = path.resolve(GIT_TMP, repoId);
-
- return fs.exists(repoPath)
- .then(function(doExists) {
- if (doExists) return;
-
- // Clone repo
- return exec("git clone "+host+" "+repoPath)
- .then(function() {
- return exec("git checkout "+ref, { cwd: repoPath });
- })
- })
- .thenResolve(repoPath);
- });
+ var isBranch = false;
+
+ ref = ref || "master";
+ if (!validateSha(ref)) isBranch = true;
+
+ return Q()
+
+ // Create temporary folder to store git repos
+ .then(function() {
+ if (GIT_TMP) return;
+ return fs.tmp.dir()
+ .then(function(_tmp) {
+ GIT_TMP = _tmp;
+ });
+ })
+
+ // Return or clone the git repo
+ .then(function() {
+ // Unique ID for repo/ref combinaison
+ var repoId = crc.crc32(host+"#"+ref).toString(16);
+
+ // Absolute path to the folder
+ var repoPath = path.resolve(GIT_TMP, repoId);
+
+ return fs.exists(repoPath)
+ .then(function(doExists) {
+ if (doExists) return;
+
+ // Clone repo
+ return exec("git clone "+host+" "+repoPath)
+ .then(function() {
+ return exec("git checkout "+ref, { cwd: repoPath });
+ })
+ })
+ .thenResolve(repoPath);
+ });
}
// Get file from a git repo
function resolveFileFromGit(giturl) {
- if (_.isString(giturl)) giturl = parseGitUrl(giturl);
- if (!giturl) return Q(null);
+ if (_.isString(giturl)) giturl = parseGitUrl(giturl);
+ if (!giturl) return Q(null);
- // Clone or get from cache
- return cloneGitRepo(giturl.host, giturl.ref)
- .then(function(repo) {
+ // Clone or get from cache
+ return cloneGitRepo(giturl.host, giturl.ref)
+ .then(function(repo) {
- // Resolve relative path
- return path.resolve(repo, giturl.filepath);
- });
+ // Resolve relative path
+ return path.resolve(repo, giturl.filepath);
+ });
};
module.exports = {
- checkUrl: checkGitUrl,
- parseUrl: parseGitUrl,
- resolveFile: resolveFileFromGit
+ checkUrl: checkGitUrl,
+ parseUrl: parseGitUrl,
+ resolveFile: resolveFileFromGit
};