-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes missing shell escape for git commit message
- Loading branch information
Showing
2 changed files
with
141 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,71 @@ | ||
var contra = require('contra'), | ||
path = require('path'), | ||
fUtils = require('./files'), | ||
cp = require('child_process'); | ||
|
||
var gitApp = 'git', gitExtra = { env: process.env }; | ||
var contra = require("contra"), | ||
path = require("path"), | ||
fUtils = require("./files"), | ||
cp = require("child_process"); | ||
|
||
var gitApp = "git", | ||
gitExtra = { env: process.env }; | ||
|
||
var escapeQuotes = function (str) { | ||
if (typeof str === 'string') { | ||
return str.replace(/(["$`\\])/g, '\\$1'); | ||
if (typeof str === "string") { | ||
return '"' + str.replace(/(["'$`\\])/g, "\\$1") + '"'; | ||
} else { | ||
return str; | ||
} | ||
}; | ||
|
||
module.exports.isRepositoryClean = function (callback) { | ||
cp.exec(gitApp + ' ' + [ 'ls-files', '-m' ].join(' '), gitExtra, function (er, stdout, stderr) { | ||
cp.exec(gitApp + " " + ["ls-files", "-m"].join(" "), gitExtra, function ( | ||
er, | ||
stdout, | ||
stderr | ||
) { | ||
// makeCommit parly inspired and taken from NPM version module | ||
var lines = stdout.trim().split('\n').filter(function (line) { | ||
var file = path.basename(line.replace(/.{1,2}\s+/, '')); | ||
return line.trim() && !line.match(/^\?\? /) && !fUtils.isPackageFile(line); | ||
}).map(function (line) { | ||
return line.trim() | ||
}); | ||
var lines = stdout | ||
.trim() | ||
.split("\n") | ||
.filter(function (line) { | ||
var file = path.basename(line.replace(/.{1,2}\s+/, "")); | ||
return ( | ||
line.trim() && !line.match(/^\?\? /) && !fUtils.isPackageFile(line) | ||
); | ||
}) | ||
.map(function (line) { | ||
return line.trim(); | ||
}); | ||
|
||
if (lines.length) { | ||
return callback(new Error('Git working directory not clean.\n'+lines.join('\n'))); | ||
return callback( | ||
new Error("Git working directory not clean.\n" + lines.join("\n")) | ||
); | ||
} | ||
return callback(); | ||
}); | ||
}; | ||
|
||
module.exports.checkout = function (callback) { | ||
cp.exec(gitApp + ' checkout -- .', gitExtra, callback); | ||
cp.exec(gitApp + " checkout -- .", gitExtra, callback); | ||
}; | ||
|
||
module.exports.commit = function (files, message, newVer, tagName, callback) { | ||
message = message.replace('%s', newVer).replace('"', '').replace("'", ''); | ||
files = files.map(function (file) { | ||
return '"' + escapeQuotes(file) + '"'; | ||
}).join(' '); | ||
message = escapeQuotes(message.replace("%s", newVer)); | ||
files = files.map(escapeQuotes).join(" "); | ||
var functionSeries = [ | ||
function (done) { | ||
cp.exec(gitApp + ' add ' + files, gitExtra, done); | ||
cp.exec(gitApp + " add " + files, gitExtra, done); | ||
}, | ||
|
||
function (done) { | ||
cp.exec([gitApp, 'commit', '-m', '"' + message + '"'].join(' '), gitExtra, done); | ||
cp.exec([gitApp, "commit", "-m", message].join(" "), gitExtra, done); | ||
}, | ||
|
||
function (done) { | ||
cp.exec( | ||
[ | ||
gitApp, 'tag', '-a', tagName, '-m', '"' + message + '"' | ||
].join(' '), | ||
gitExtra, done | ||
[gitApp, "tag", "-a", tagName, "-m", message].join(" "), | ||
gitExtra, | ||
done | ||
); | ||
} | ||
}, | ||
]; | ||
contra.series(functionSeries, callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters