diff options
author | Bradley Meck <bradley.meck@gmail.com> | 2014-06-25 21:30:50 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-06-28 02:06:53 +0400 |
commit | 59eb112eec7bfd0e39b6098142d76ad66d3aca14 (patch) | |
tree | 5f76e7c7f1dd2892d38b2c69b6349fbc8e06955b /lib | |
parent | 91733e288170fb50db631d55f9dfd33b60820b7d (diff) |
Use core.longpaths on win32 git - fixes #5525
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cache/add-remote-git.js | 69 | ||||
-rw-r--r-- | lib/submodule.js | 64 | ||||
-rw-r--r-- | lib/utils/git.js | 45 | ||||
-rw-r--r-- | lib/version.js | 62 |
4 files changed, 114 insertions, 126 deletions
diff --git a/lib/cache/add-remote-git.js b/lib/cache/add-remote-git.js index bbe38b0e5..7743aa4a4 100644 --- a/lib/cache/add-remote-git.js +++ b/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") diff --git a/lib/submodule.js b/lib/submodule.js index 544433af5..2231ced9c 100644 --- a/lib/submodule.js +++ b/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) }) } diff --git a/lib/utils/git.js b/lib/utils/git.js new file mode 100644 index 000000000..6f8131aa7 --- /dev/null +++ b/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) + }) +} diff --git a/lib/version.js b/lib/version.js index 5551d4cd9..f708f82a0 100644 --- a/lib/version.js +++ b/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) { |