Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: npm/npm
...
head fork: bmeck/npm
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
69 lib/cache/add-remote-git.js
@@ -1,7 +1,6 @@
var mkdir = require("mkdirp")
, assert = require("assert")
- , spawn = require("child_process").spawn
- , exec = require("child_process").execFile
+ , git = require("../utils/git.js")
, once = require("once")
, fs = require("graceful-fs")
, log = require("npmlog")
@@ -86,29 +85,22 @@ function checkGitDir (p, u, co, origUrl, silent, cb) {
cloneGitRemote(p, u, co, origUrl, silent, cb)
})
- var git = npm.config.get("git")
var args = [ "config", "--get", "remote.origin.url" ]
var env = gitEnv()
// check for git
- which(git, function (err) {
- if (err) {
- err.code = "ENOGIT"
- return cb(err)
+ git.whichAndExec(args, {cwd: p, env: env}, function (er, stdout, stderr) {
+ var stdoutTrimmed = (stdout + "\n" + stderr).trim()
+ if (er || u !== stdout.trim()) {
+ log.warn( "`git config --get remote.origin.url` returned "
+ + "wrong result ("+u+")", stdoutTrimmed )
+ return rm(p, function (er){
+ if (er) return cb(er)
+ cloneGitRemote(p, u, co, origUrl, silent, cb)
+ })
}
- exec(git, args, {cwd: p, env: env}, function (er, stdout, stderr) {
- var stdoutTrimmed = (stdout + "\n" + stderr).trim()
- if (er || u !== stdout.trim()) {
- log.warn( "`git config --get remote.origin.url` returned "
- + "wrong result ("+u+")", stdoutTrimmed )
- return rm(p, function (er){
- if (er) return cb(er)
- cloneGitRemote(p, u, co, origUrl, silent, cb)
- })
- }
- log.verbose("git remote.origin.url", stdoutTrimmed)
- archiveGitRemote(p, u, co, origUrl, cb)
- })
+ log.verbose("git remote.origin.url", stdoutTrimmed)
+ archiveGitRemote(p, u, co, origUrl, cb)
})
})
}
@@ -117,35 +109,27 @@ function cloneGitRemote (p, u, co, origUrl, silent, cb) {
mkdir(p, function (er) {
if (er) return cb(er)
- var git = npm.config.get("git")
var args = [ "clone", "--mirror", u, p ]
var env = gitEnv()
// check for git
- which(git, function (err) {
- if (err) {
- err.code = "ENOGIT"
- return cb(err)
- }
- exec(git, args, {cwd: p, env: env}, function (er, stdout, stderr) {
- stdout = (stdout + "\n" + stderr).trim()
- if (er) {
- if (silent) {
- log.verbose("git clone " + u, stdout)
- } else {
- log.error("git clone " + u, stdout)
- }
- return cb(er)
+ git.whichAndExec(args, {cwd: p, env: env}, function (er, stdout, stderr) {
+ stdout = (stdout + "\n" + stderr).trim()
+ if (er) {
+ if (silent) {
+ log.verbose("git clone " + u, stdout)
+ } else {
+ log.error("git clone " + u, stdout)
}
- log.verbose("git clone " + u, stdout)
- archiveGitRemote(p, u, co, origUrl, cb)
- })
+ return cb(er)
+ }
+ log.verbose("git clone " + u, stdout)
+ archiveGitRemote(p, u, co, origUrl, cb)
})
})
}
function archiveGitRemote (p, u, co, origUrl, cb) {
- var git = npm.config.get("git")
var archive = [ "fetch", "-a", "origin" ]
var resolve = [ "rev-list", "-n1", co ]
var env = gitEnv()
@@ -153,7 +137,7 @@ function archiveGitRemote (p, u, co, origUrl, cb) {
var resolved = null
var tmp
- exec(git, archive, {cwd: p, env: env}, function (er, stdout, stderr) {
+ git.whichAndExec(archive, {cwd: p, env: env}, function (er, stdout, stderr) {
stdout = (stdout + "\n" + stderr).trim()
if (er) {
log.error("git fetch -a origin ("+u+")", stdout)
@@ -186,7 +170,7 @@ function archiveGitRemote (p, u, co, origUrl, cb) {
}
function resolveHead () {
- exec(git, resolve, {cwd: p, env: env}, function (er, stdout, stderr) {
+ git.whichAndExec(resolve, {cwd: p, env: env}, function (er, stdout, stderr) {
stdout = (stdout + "\n" + stderr).trim()
if (er) {
log.error("Failed resolving git HEAD (" + u + ")", stderr)
@@ -215,12 +199,11 @@ function archiveGitRemote (p, u, co, origUrl, cb) {
mkdir(path.dirname(tmp), function (er) {
if (er) return cb(er)
var gzip = zlib.createGzip({ level: 9 })
- var git = npm.config.get("git")
var args = ["archive", co, "--format=tar", "--prefix=package/"]
var out = fs.createWriteStream(tmp)
var env = gitEnv()
cb = once(cb)
- var cp = spawn(git, args, { env: env, cwd: p })
+ var cp = git.spawn(args, { env: env, cwd: p })
cp.on("error", cb)
cp.stderr.on("data", function(chunk) {
log.silly(chunk.toString(), "git archive")
View
64 lib/submodule.js
@@ -5,8 +5,8 @@
module.exports = submodule
var npm = require("./npm.js")
- , exec = require("child_process").execFile
, cache = require("./cache.js")
+ , git = require("./utils/git.js")
, asyncMap = require("slide").asyncMap
, chain = require("slide").chain
, which = require("which")
@@ -56,64 +56,36 @@ function submodule_ (pkg, cb) {
}
function updateSubmodule (name, cb) {
- var git = npm.config.get("git")
var args = [ "submodule", "update", "--init", "node_modules/", name ]
- // check for git
- which(git, function (err) {
- if (err) {
- err.code = "ENOGIT"
- return cb(err)
- }
-
- exec(git, args, cb)
- })
+ git.whichAndExec(args, cb)
}
function addSubmodule (name, url, cb) {
- var git = npm.config.get("git")
var args = [ "submodule", "add", url, "node_modules/", name ]
- // check for git
- which(git, function (err) {
- if (err) {
- err.code = "ENOGIT"
- return cb(err)
- }
-
- exec(git, args, function (er) {
- if (er) return cb(er)
- updateSubmodule(name, cb)
- })
- })
+ git.whichAndExec(args, cb)
}
var getSubmodules = function (cb) {
- var git = npm.config.get("git")
var args = [ "submodule", "status" ]
- // check for git
- which(git, function (err) {
- if (err) {
- err.code = "ENOGIT"
- return cb(err)
- }
- exec(git, args, function (er, stdout) {
- if (er) return cb(er)
- var res = stdout.trim().split(/\n/).map(function (line) {
- return line.trim().split(/\s+/)[1]
- }).filter(function (line) {
- // only care about submodules in the node_modules folder.
- return line && line.match(/^node_modules\//)
- }).map(function (line) {
- return line.replace(/^node_modules\//g, "")
- })
-
- // memoize.
- getSubmodules = function (cb) { return cb(null, res) }
-
- cb(null, res)
+
+ git.whichAndExec(args, function _(er, stdout) {
+ if (er) return cb(er)
+ var res = stdout.trim().split(/\n/).map(function (line) {
+ return line.trim().split(/\s+/)[1]
+ }).filter(function (line) {
+ // only care about submodules in the node_modules folder.
+ return line && line.match(/^node_modules\//)
+ }).map(function (line) {
+ return line.replace(/^node_modules\//g, "")
})
+
+ // memoize.
+ getSubmodules = function (cb) { return cb(null, res) }
+
+ cb(null, res)
})
}
View
45 lib/utils/git.js
@@ -0,0 +1,45 @@
+
+// handle some git configuration for windows
+
+exports.spawn = spawnGit
+exports.chainableExec = chainableExec
+exports.whichAndExec = whichAndExec
+
+var exec = require("child_process").execFile
+ , spawn = require("child_process").spawn
+ , npm = require("../npm.js")
+ , which = require("which")
+ , git = npm.config.get("git")
+
+function prefixGitArgs() {
+ return process.platform === "win32" ? ["-c", "core.longpaths=true"] : []
+}
+
+function execGit(args, options, cb) {
+ return exec(git, prefixGitArgs().concat(args || []), options, cb)
+}
+
+function spawnGit(args, options, cb) {
+ return spawn(git, prefixGitArgs().concat(args || []), options)
+}
+
+function chainableExec() {
+ var args = Array.prototype.slice.call(arguments)
+ return [gitExec].concat(args)
+}
+
+function whichGit(cb) {
+ return which(git, cb)
+}
+
+function whichAndExec(args, options, cb) {
+ // check for git
+ whichGit(function (err) {
+ if (err) {
+ err.code = "ENOGIT"
+ return cb(err)
+ }
+
+ execGit(args, options, cb)
+ })
+}
View
62 lib/version.js
@@ -74,48 +74,36 @@ function version (args, silent, cb_) {
}
function checkGit (data, cb) {
- var git = npm.config.get("git")
var args = [ "status", "--porcelain" ]
- var env = process.env
+ var options = {env: process.env}
// check for git
- which(git, function (err) {
- if (err) {
- err.code = "ENOGIT"
- return cb(err)
- }
-
- gitFound()
- })
-
- function gitFound () {
- exec(git, args, {env: env}, function (er, stdout) {
- var lines = stdout.trim().split("\n").filter(function (line) {
- return line.trim() && !line.match(/^\?\? /)
- }).map(function (line) {
- return line.trim()
- })
- if (lines.length) return cb(new Error(
- "Git working directory not clean.\n"+lines.join("\n")))
- write(data, function (er) {
- if (er) return cb(er)
- var message = npm.config.get("message").replace(/%s/g, data.version)
- , sign = npm.config.get("sign-git-tag")
- , flag = sign ? "-sm" : "-am"
- chain
- ( [ [ exec, git, [ "add", "package.json" ], {env: process.env} ]
- , [ exec, git, [ "commit", "-m", message ], {env: process.env} ]
- , sign && function (cb) {
- npm.spinner.stop()
- cb()
- }
+ git.whichAndExec(args, options, function (er, stdout) {
+ var lines = stdout.trim().split("\n").filter(function (line) {
+ return line.trim() && !line.match(/^\?\? /)
+ }).map(function (line) {
+ return line.trim()
+ })
+ if (lines.length) return cb(new Error(
+ "Git working directory not clean.\n"+lines.join("\n")))
+ write(data, function (er) {
+ if (er) return cb(er)
+ var message = npm.config.get("message").replace(/%s/g, data.version)
+ , sign = npm.config.get("sign-git-tag")
+ , flag = sign ? "-sm" : "-am"
+ chain
+ ( [ git.chainableExec([ "add", "package.json" ], {env: process.env})
+ , git.chainableExec([ "commit", "-m", message ], {env: process.env})
+ , sign && function (cb) {
+ npm.spinner.stop()
+ cb()
+ }
- , [ exec, git, [ "tag", "v" + data.version, flag, message ]
- , {env: process.env} ] ]
- , cb )
- })
+ , git.chainableExec([ "tag", "v" + data.version, flag, message ]
+ , {env: process.env}) ]
+ , cb )
})
- }
+ })
}
function write (data, cb) {

No commit comments for this range

Something went wrong with that request. Please try again.