aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristophe Porteneuve <[email protected]>2013-11-08 19:07:36 +0100
committerChristophe Porteneuve <[email protected]>2013-11-08 19:35:25 +0100
commit36c62aff7424b12ca9e84370afc65ecfbe73e632 (patch)
tree9f98811e5acb166b4a2a235ef58103cb0fec4404 /lib
parent335918f28d6cbbac2efbc25990e97549dbd96aee (diff)
downloadnode-coveralls-36c62aff7424b12ca9e84370afc65ecfbe73e632.tar.xz
node-coveralls-36c62aff7424b12ca9e84370afc65ecfbe73e632.zip
Fix step 2: properly detect local Git branch, and just keep pre-provided one if any.
Diffstat (limited to 'lib')
-rw-r--r--lib/fetchGitData.js71
1 files changed, 40 insertions, 31 deletions
diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js
index a77b4a8..f75ca82 100644
--- a/lib/fetchGitData.js
+++ b/lib/fetchGitData.js
@@ -25,7 +25,6 @@ var fetchGitData = function(git, cb) {
"format": "'%s'",
}
};
- var remotes = {};
//-- Malformed/undefined git object
if ('undefined' === typeof git) {
@@ -36,22 +35,6 @@ var fetchGitData = function(git, cb) {
return cb(new Error('You must provide the head.id'));
}
- function saveRemote(name, url, push) {
- var key = name + "-" + url;
- if ("undefined" === typeof push || "boolean" !== typeof push) {
- push = true;
- }
- if (!remotes.hasOwnProperty(key)) {
- remotes[key] = true;
- if (push) {
- git.remotes.push({
- "name": name,
- "url": url
- });
- }
- }
- }
-
//-- Set required properties of git if they weren"t provided
if (!git.hasOwnProperty("branch")) {
git.branch = "";
@@ -98,24 +81,50 @@ var fetchGitData = function(git, cb) {
git.head[field] = response;
remaining--;
if (remaining === 0){
- //-- Branch
- exec("git branch", function(err, branches){
- if (err) return cb(err);
- git.branch = branches.split("\n")[0].replace(/^\*\ /, "").trim();
- exec("git remote -v", function(err, remotes){
- if (err) return cb(err);
- remotes.split("\n").forEach(function(remote) {
- remote = remote.split(/\s/);
- saveRemote(remote[0], remote[1]);
- });
- return cb(null, git);
- });
- });
+ if (git.branch) {
+ fetchRemotes(git, cb);
+ } else {
+ fetchBranch(git, cb);
+ }
}
});
});
});
-};
+}
+
+function fetchBranch(git, cb) {
+ exec("git branch", function(err, branches){
+ if (err)
+ return cb(err);
+
+ git.branch = (branches.match(/^\* (\w+)/) || [])[1];
+ fetchRemotes(git, cb);
+ });
+}
+
+function fetchRemotes(git, cb) {
+ exec("git remote -v", function(err, remotes){
+ if (err)
+ return cb(err);
+
+ var processed = {};
+ remotes.split("\n").forEach(function(remote) {
+ if (!/\s\(push\)$/.test(remote))
+ return;
+ remote = remote.split(/\s+/);
+ saveRemote(processed, git, remote[0], remote[1]);
+ });
+ cb(null, git);
+ });
+}
+
+function saveRemote(processed, git, name, url) {
+ var key = name + "-" + url;
+ if (processed.hasOwnProperty(key))
+ return;
+ processed[key] = true;
+ git.remotes.push({ name: name, url: url });
+}
module.exports = fetchGitData;