git-diff-apply
Advanced tools
Comparing version 0.20.6 to 0.21.0
@@ -40,10 +40,26 @@ #!/usr/bin/env node | ||
argv.wasRunAsExecutable = true; | ||
(async() => { | ||
let options = { | ||
cwd: process.cwd(), | ||
...argv | ||
}; | ||
(async() => { | ||
let returnObject; | ||
try { | ||
await gitDiffApply(argv); | ||
returnObject = await gitDiffApply(options); | ||
} catch (err) { | ||
console.log(err); | ||
return; | ||
} | ||
let ps = returnObject.resolveConflictsProcess; | ||
if (ps) { | ||
process.stdin.pipe(ps.stdin); | ||
ps.stdout.pipe(process.stdout); | ||
ps.stderr.pipe(process.stderr); | ||
// since we are piping, not inheriting, the child process | ||
// doesn't have the power to close its parent | ||
ps.on('exit', process.exit); | ||
} | ||
})(); |
{ | ||
"name": "git-diff-apply", | ||
"version": "0.20.6", | ||
"version": "0.21.0", | ||
"description": "Use an unrelated remote repository to apply a git diff", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -5,5 +5,5 @@ 'use strict'; | ||
module.exports = async function checkOutTag(repoDir, tag) { | ||
let sha = await run(`git rev-parse ${tag}`, { cwd: repoDir }); | ||
await run(`git checkout ${sha.trim()}`, { cwd: repoDir }); | ||
module.exports = async function checkOutTag(tag, options) { | ||
let sha = await run(`git rev-parse ${tag}`, options); | ||
await run(`git checkout ${sha.trim()}`, options); | ||
}; |
@@ -5,5 +5,5 @@ 'use strict'; | ||
module.exports = async function getRootDir() { | ||
let root = (await run('git rev-parse --show-toplevel')).trim(); | ||
module.exports = async function getRootDir(options) { | ||
let root = (await run('git rev-parse --show-toplevel', options)).trim(); | ||
return root; | ||
}; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
module.exports = async function getSubDir() { | ||
module.exports = async function getSubDir(options) { | ||
// `git rev-parse --show-toplevel` won't work to determine root. | ||
@@ -14,5 +14,5 @@ // On GitHub Actions, `process.cwd()` returns 8.3 filenames, | ||
// not bahave as expected. | ||
let relative = (await run('git rev-parse --show-cdup')).trim(); | ||
let subDir = path.relative(relative, process.cwd()); | ||
let relative = (await run('git rev-parse --show-cdup', options)).trim(); | ||
let subDir = path.relative(path.resolve(options.cwd, relative), options.cwd); | ||
return subDir; | ||
}; |
@@ -35,2 +35,3 @@ 'use strict'; | ||
module.exports = async function gitDiffApply({ | ||
cwd, | ||
remoteUrl, | ||
@@ -45,4 +46,3 @@ startTag, | ||
startCommand, | ||
endCommand, | ||
wasRunAsExecutable | ||
endCommand | ||
}) { | ||
@@ -63,3 +63,2 @@ let _tmpDir; | ||
let root; | ||
let cwd; | ||
let gitIgnoredFiles; | ||
@@ -75,3 +74,3 @@ | ||
} else { | ||
await checkOutTag(_tmpDir, startTag); | ||
await checkOutTag(startTag, { cwd: _tmpDir }); | ||
@@ -81,3 +80,3 @@ from = convertToObj(_tmpDir, ignoredFiles); | ||
await checkOutTag(_tmpDir, endTag); | ||
await checkOutTag(endTag, { cwd: _tmpDir }); | ||
@@ -102,3 +101,3 @@ let to = convertToObj(_tmpDir, ignoredFiles); | ||
await checkOutTag(_tmpDir, tag); | ||
await checkOutTag(tag, { cwd: _tmpDir }); | ||
@@ -130,7 +129,7 @@ await utils.copy(_tmpDir, newTmpSubDir); | ||
// `git checkout` will fail unless it is also tracked. | ||
let isTracked = await utils.run(`git ls-files ${ignoredFile}`); | ||
let isTracked = await utils.run(`git ls-files ${ignoredFile}`, { cwd }); | ||
if (isTracked) { | ||
await utils.run(`git checkout -- ${ignoredFile}`); | ||
await utils.run(`git checkout -- ${ignoredFile}`, { cwd }); | ||
} else { | ||
await fs.remove(ignoredFile); | ||
await fs.remove(path.join(cwd, ignoredFile)); | ||
} | ||
@@ -151,3 +150,3 @@ } | ||
// https://stackoverflow.com/questions/6308625/how-to-avoid-git-apply-changing-line-endings#comment54419617_11189296 | ||
await utils.run(`git apply --whitespace=fix ${patchFile}`); | ||
await utils.run(`git apply --whitespace=fix ${patchFile}`, { cwd }); | ||
} | ||
@@ -157,3 +156,3 @@ | ||
if (reset || init) { | ||
await checkOutTag(_tmpDir, endTag); | ||
await checkOutTag(endTag, { cwd: _tmpDir }); | ||
@@ -168,3 +167,3 @@ isCodeUntracked = true; | ||
await utils.run('git reset'); | ||
await utils.run('git reset', { cwd }); | ||
@@ -176,6 +175,6 @@ await resetIgnoredFiles(); | ||
await checkOutTag(_tmpDir, startTag); | ||
await checkOutTag(startTag, { cwd: _tmpDir }); | ||
oldBranchName = await getCheckedOutBranchName(); | ||
await utils.run(`git checkout --orphan ${tempBranchName}`); | ||
oldBranchName = await getCheckedOutBranchName({ cwd }); | ||
await utils.run(`git checkout --orphan ${tempBranchName}`, { cwd }); | ||
isTempBranchCheckedOut = true; | ||
@@ -193,3 +192,3 @@ | ||
isTempBranchCommitted = true; | ||
await commit(); | ||
await commit({ cwd }); | ||
isCodeUntracked = false; | ||
@@ -208,6 +207,6 @@ | ||
let wereAnyChanged = !await isGitClean(); | ||
let wereAnyChanged = !await isGitClean({ cwd }); | ||
if (wereAnyChanged) { | ||
await commit(); | ||
await commit({ cwd }); | ||
} | ||
@@ -219,6 +218,6 @@ isCodeUntracked = false; | ||
if (wereAnyChanged) { | ||
sha = await utils.run('git rev-parse HEAD'); | ||
sha = await utils.run('git rev-parse HEAD', { cwd }); | ||
} | ||
await utils.run(`git checkout ${oldBranchName}`); | ||
await utils.run(`git checkout ${oldBranchName}`, { cwd }); | ||
isTempBranchCheckedOut = false; | ||
@@ -228,3 +227,3 @@ | ||
try { | ||
await utils.run(`git cherry-pick --no-commit ${sha.trim()}`); | ||
await utils.run(`git cherry-pick --no-commit ${sha.trim()}`, { cwd }); | ||
} catch (err) { | ||
@@ -244,3 +243,3 @@ hasConflicts = true; | ||
try { | ||
isClean = await isGitClean(); | ||
isClean = await isGitClean({ cwd }); | ||
} catch (err) { | ||
@@ -274,4 +273,4 @@ throw 'Not a git repository'; | ||
root = await getRootDir(); | ||
let subDir = await getSubDir(root); | ||
root = await getRootDir({ cwd }); | ||
let subDir = await getSubDir({ cwd }); | ||
if (subDir) { | ||
@@ -283,4 +282,2 @@ debug('subDir', subDir); | ||
cwd = process.cwd(); | ||
await go(); | ||
@@ -294,6 +291,6 @@ | ||
if (isCodeUntracked) { | ||
await utils.run('git clean -f'); | ||
await utils.run('git clean -f', { cwd }); | ||
} | ||
if (isCodeModified) { | ||
await utils.run('git reset --hard'); | ||
await utils.run('git reset --hard', { cwd }); | ||
} | ||
@@ -310,7 +307,7 @@ } catch (err2) { | ||
if (isTempBranchCheckedOut) { | ||
await utils.run(`git checkout ${oldBranchName}`); | ||
await utils.run(`git checkout ${oldBranchName}`, { cwd }); | ||
} | ||
if (isTempBranchCommitted && await doesBranchExist(tempBranchName)) { | ||
await utils.run(`git branch -D ${tempBranchName}`); | ||
if (isTempBranchCommitted && await doesBranchExist(tempBranchName, { cwd })) { | ||
await utils.run(`git branch -D ${tempBranchName}`, { cwd }); | ||
} | ||
@@ -335,5 +332,3 @@ | ||
if (hasConflicts && _resolveConflicts) { | ||
returnObject.resolveConflictsProcess = resolveConflicts({ | ||
shouldPipe: !wasRunAsExecutable | ||
}); | ||
returnObject.resolveConflictsProcess = resolveConflicts({ cwd }); | ||
} | ||
@@ -340,0 +335,0 @@ |
@@ -6,11 +6,7 @@ 'use strict'; | ||
module.exports = function resolveConflicts({ | ||
shouldPipe | ||
}) { | ||
module.exports = function resolveConflicts(options) { | ||
debug('git mergetool'); | ||
// we need to print it to the host's console | ||
// or make it available for piping | ||
return spawn('git', ['mergetool'], { | ||
stdio: shouldPipe ? 'pipe' : 'inherit' | ||
}); | ||
// pipe for those using as a library can interact | ||
return spawn('git', ['mergetool'], options); | ||
}; |
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
21558
604