[Pkg-javascript-commits] [node-coveralls] 104/332: Fix step 2: properly detect local Git branch, and just keep pre-provided one if any.
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 13:53:46 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-coveralls.
commit 36c62aff7424b12ca9e84370afc65ecfbe73e632
Author: Christophe Porteneuve <tdd at tddsworld.com>
Date: Fri Nov 8 19:07:36 2013 +0100
Fix step 2: properly detect local Git branch, and just keep pre-provided one if any.
---
lib/fetchGitData.js | 71 ++++++++++++++++++++++++++++++-----------------------
1 file 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;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coveralls.git
More information about the Pkg-javascript-commits
mailing list