git-diff-apply
Advanced tools
Comparing version 0.22.8 to 0.22.9
{ | ||
"name": "git-diff-apply", | ||
"version": "0.22.8", | ||
"version": "0.22.9", | ||
"description": "Use an unrelated remote repository to apply a git diff", | ||
@@ -42,3 +42,2 @@ "main": "src", | ||
"debug": "^4.0.0", | ||
"execa": "^3.2.0", | ||
"fixturify": "^1.0.0", | ||
@@ -45,0 +44,0 @@ "fs-extra": "^8.0.0", |
'use strict'; | ||
const run = require('./run'); | ||
const { runWithSpawn } = require('./run'); | ||
module.exports = async function checkOutTag(tag, options) { | ||
let sha = await run(`git rev-parse ${tag}`, options); | ||
await run(`git checkout ${sha.trim()}`, options); | ||
let sha = await runWithSpawn('git', ['rev-parse', tag], options); | ||
await runWithSpawn('git', ['checkout', sha.trim()], options); | ||
}; |
'use strict'; | ||
const commit = require('./commit'); | ||
const run = require('./run'); | ||
const { runWithSpawn } = require('./run'); | ||
module.exports = async function commitAndTag(tag, options) { | ||
await commit(tag, options); | ||
await run(`git tag ${tag}`, options); | ||
await runWithSpawn('git', ['tag', tag], options); | ||
}; |
'use strict'; | ||
const run = require('./run'); | ||
const utils = require('./utils'); | ||
const { runWithSpawn } = require('./run'); | ||
module.exports = async function commit(message, options) { | ||
await run('git add -A', options); | ||
await runWithSpawn('git', ['add', '-A'], options); | ||
@@ -12,3 +11,3 @@ // run with --no-verify to skip pre-commit application level hooks | ||
// or the second commit has no changes | ||
await utils.run(`git commit --allow-empty -m "${message}" --no-verify`, options); | ||
await runWithSpawn('git', ['commit', '--allow-empty', '-m', message, '--no-verify'], options); | ||
}; |
'use strict'; | ||
const run = require('./run'); | ||
const { runWithSpawn } = run; | ||
const gitInit = require('./git-init'); | ||
@@ -26,3 +27,3 @@ const commitAndTag = require('./commit-and-tag'); | ||
// This will work around that, | ||
await run('git config core.autocrlf true', { | ||
await runWithSpawn('git', ['config', 'core.autocrlf', 'true'], { | ||
cwd | ||
@@ -29,0 +30,0 @@ }); |
'use strict'; | ||
const run = require('./run'); | ||
const { runWithSpawn } = require('./run'); | ||
module.exports = async function getRootDir(options) { | ||
let root = (await run('git rev-parse --show-toplevel', options)).trim(); | ||
let root = (await runWithSpawn('git', ['rev-parse', '--show-toplevel'], options)).trim(); | ||
return root; | ||
}; |
'use strict'; | ||
const path = require('path'); | ||
const run = require('./run'); | ||
const { runWithSpawn } = require('./run'); | ||
@@ -13,5 +13,5 @@ module.exports = async function getSubDir(options) { | ||
// not bahave as expected. | ||
let relative = (await run('git rev-parse --show-cdup', options)).trim(); | ||
let relative = (await runWithSpawn('git', ['rev-parse', '--show-cdup'], options)).trim(); | ||
let subDir = path.relative(path.resolve(options.cwd, relative), options.cwd); | ||
return subDir; | ||
}; |
'use strict'; | ||
const run = require('./run'); | ||
const { runWithSpawn } = require('./run'); | ||
async function gitInit(options) { | ||
await run('git init', options); | ||
await runWithSpawn('git', ['init'], options); | ||
await gitConfigInit(options); | ||
@@ -11,11 +11,11 @@ } | ||
async function gitConfigInit(options) { | ||
await run('git config user.email "you@example.com"', options); | ||
await run('git config user.name "Your Name"', options); | ||
await runWithSpawn('git', ['config', 'user.email', 'you@example.com'], options); | ||
await runWithSpawn('git', ['config', 'user.name', 'Your Name'], options); | ||
// ignore any global .gitignore that will mess with us | ||
await run('git config core.excludesfile false', options); | ||
await runWithSpawn('git', ['config', 'core.excludesfile', 'false'], options); | ||
// this global setting messes with diffs | ||
// https://github.com/ember-cli/ember-cli-update/issues/995 | ||
await run('git config diff.noprefix false', options); | ||
await runWithSpawn('git', ['config', 'diff.noprefix', 'false'], options); | ||
} | ||
@@ -22,0 +22,0 @@ |
@@ -12,3 +12,4 @@ 'use strict'; | ||
let files = (await runWithSpawn('git', ['ls-files'], options)) | ||
.split(/\r?\n/g); | ||
.split(/\r?\n/g) | ||
.filter(Boolean); | ||
@@ -41,3 +42,3 @@ return files; | ||
// when in a monorepo | ||
// await run('git rm -rf .', options); | ||
// await runWithSpawn('git', ['rm', '-rf', '.'], options); | ||
@@ -50,3 +51,3 @@ let files = await lsFiles(options); | ||
// which we are trying to avoid | ||
// await run(`git rm -f "${file}"`, options); | ||
// await runWithSpawn('git', ['rm', '-f', file], options); | ||
for (let file of files) { | ||
@@ -53,0 +54,0 @@ await fs.remove(path.join(options.cwd, file)); |
@@ -21,3 +21,4 @@ 'use strict'; | ||
const createCustomRemote = require('./create-custom-remote'); | ||
const { runWithSpawn } = require('./run'); | ||
const run = require('./run'); | ||
const { runWithSpawn } = run; | ||
@@ -136,5 +137,5 @@ const { isGitClean } = gitStatus; | ||
// `git checkout` will fail unless it is also tracked. | ||
let isTracked = await utils.run(`git ls-files ${ignoredFile}`, { cwd }); | ||
let isTracked = await runWithSpawn('git', ['ls-files', ignoredFile], { cwd }); | ||
if (isTracked) { | ||
await utils.run(`git checkout -- ${ignoredFile}`, { cwd }); | ||
await runWithSpawn('git', ['checkout', '--', ignoredFile], { cwd }); | ||
} else { | ||
@@ -148,3 +149,5 @@ await fs.remove(path.join(cwd, ignoredFile)); | ||
let patchFile = path.join(await tmpDir(), 'file.patch'); | ||
await utils.run(`git diff ${safeStartTag} ${safeEndTag} --binary > ${patchFile}`, { cwd: _tmpDir }); | ||
let ps = runWithSpawn('git', ['diff', safeStartTag, safeEndTag, '--binary'], { cwd: _tmpDir }); | ||
ps.stdout.pipe(fs.createWriteStream(patchFile)); | ||
await ps; | ||
if (await fs.readFile(patchFile, 'utf8') !== '') { | ||
@@ -158,3 +161,3 @@ return patchFile; | ||
// https://stackoverflow.com/questions/6308625/how-to-avoid-git-apply-changing-line-endings#comment54419617_11189296 | ||
await utils.run(`git apply --whitespace=fix ${patchFile}`, { cwd: _tmpDir }); | ||
await runWithSpawn('git', ['apply', '--whitespace=fix', patchFile], { cwd: _tmpDir }); | ||
} | ||
@@ -174,3 +177,3 @@ | ||
await utils.run('git reset', { cwd }); | ||
await utils.runWithSpawn('git', ['reset'], { cwd }); | ||
@@ -184,4 +187,4 @@ await resetIgnoredFiles(cwd); | ||
await utils.run(`git branch ${tempBranchName}`, { cwd: _tmpDir }); | ||
await utils.run(`git checkout ${tempBranchName}`, { cwd: _tmpDir }); | ||
await runWithSpawn('git', ['branch', tempBranchName], { cwd: _tmpDir }); | ||
await runWithSpawn('git', ['checkout', tempBranchName], { cwd: _tmpDir }); | ||
@@ -204,9 +207,9 @@ let patchFile = await createPatchFile(); | ||
let sha = await utils.run('git rev-parse HEAD', { cwd: _tmpDir }); | ||
let sha = await runWithSpawn('git', ['rev-parse', 'HEAD'], { cwd: _tmpDir }); | ||
await utils.run(`git remote add ${tempBranchName} ${_tmpDir}`, { cwd }); | ||
await utils.run(`git fetch --no-tags ${tempBranchName}`, { cwd }); | ||
await runWithSpawn('git', ['remote', 'add', tempBranchName, _tmpDir], { cwd }); | ||
await runWithSpawn('git', ['fetch', '--no-tags', tempBranchName], { cwd }); | ||
try { | ||
await utils.run(`git cherry-pick --no-commit ${sha.trim()}`, { cwd }); | ||
await runWithSpawn('git', ['cherry-pick', '--no-commit', sha.trim()], { cwd }); | ||
} catch (err) { | ||
@@ -216,3 +219,3 @@ hasConflicts = true; | ||
await utils.run(`git remote remove ${tempBranchName}`, { cwd }); | ||
await runWithSpawn('git', ['remote', 'remove', tempBranchName], { cwd }); | ||
} | ||
@@ -277,6 +280,6 @@ } | ||
if (isCodeUntracked) { | ||
await utils.run('git clean -f', { cwd }); | ||
await runWithSpawn('git', ['clean', '-f'], { cwd }); | ||
} | ||
if (isCodeModified) { | ||
await utils.run('git reset --hard', { cwd }); | ||
await runWithSpawn('git', ['reset', '--hard'], { cwd }); | ||
} | ||
@@ -304,3 +307,3 @@ } catch (err2) { | ||
module.exports.run = utils.run; | ||
module.exports.run = run; | ||
module.exports.gitInit = gitInit; | ||
@@ -307,0 +310,0 @@ module.exports.gitStatus = gitStatus; |
'use strict'; | ||
const { promisify } = require('util'); | ||
const { exec } = require('child_process'); | ||
const execa = require('execa'); | ||
const { exec, spawn } = require('child_process'); | ||
const debug = require('debug')('git-diff-apply'); | ||
@@ -16,8 +15,31 @@ const execPromise = promisify(exec); | ||
module.exports.runWithSpawn = async function runWithSpawn(cmd, args, options) { | ||
module.exports.runWithSpawn = function runWithSpawn(cmd, args, options) { | ||
let command = [cmd, ...args].join(' '); | ||
debug(command); | ||
let { stdout } = await execa(cmd, args, options); | ||
debug(stdout); | ||
return stdout; | ||
let child = spawn(cmd, args, options); | ||
let promise = new Promise(function(resolve, reject) { | ||
let stdout = ''; | ||
let errorMessage = ''; | ||
child.stdout.on('data', function(data) { | ||
stdout += data; | ||
}); | ||
child.stderr.on('data', function(data) { | ||
errorMessage += data; | ||
}); | ||
child.on('close', function(status) { | ||
if (status === 0) { | ||
debug(stdout); | ||
resolve(stdout); | ||
} else { | ||
reject(new Error(`${command} failed with message ${errorMessage}`)); | ||
} | ||
}); | ||
}); | ||
return Object.assign(promise, child); | ||
}; |
'use strict'; | ||
module.exports.copy = require('./copy'); | ||
module.exports.run = require('./run'); | ||
module.exports.runWithSpawn = require('./run').runWithSpawn; | ||
module.exports.gitRemoveAll = require('./git-remove-all'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19845
6
526
- Removedexeca@^3.2.0
- Removedcross-spawn@7.0.6(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexeca@3.4.0(transitive)
- Removedget-stream@5.2.0(transitive)
- Removedhuman-signals@1.1.1(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedisexe@2.0.0(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removednpm-run-path@4.0.1(transitive)
- Removedonetime@5.1.2(transitive)
- Removedp-finally@2.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpump@3.0.2(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-final-newline@2.0.0(transitive)
- Removedwhich@2.0.2(transitive)