git-diff-apply
Advanced tools
Comparing version 0.21.0 to 0.22.0
@@ -41,10 +41,5 @@ #!/usr/bin/env node | ||
(async() => { | ||
let options = { | ||
cwd: process.cwd(), | ||
...argv | ||
}; | ||
let returnObject; | ||
try { | ||
returnObject = await gitDiffApply(options); | ||
returnObject = await gitDiffApply(argv); | ||
} catch (err) { | ||
@@ -51,0 +46,0 @@ console.log(err); |
{ | ||
"name": "git-diff-apply", | ||
"version": "0.21.0", | ||
"version": "0.22.0", | ||
"description": "Use an unrelated remote repository to apply a git diff", | ||
@@ -47,3 +47,2 @@ "main": "src", | ||
"fs-extra": "^8.0.0", | ||
"klaw": "^3.0.0", | ||
"tmp": "0.1.0", | ||
@@ -50,0 +49,0 @@ "uuid": "^3.1.0", |
@@ -5,4 +5,8 @@ 'use strict'; | ||
module.exports = async function gitInit(options) { | ||
async function gitInit(options) { | ||
await run('git init', options); | ||
await gitConfigInit(options); | ||
} | ||
async function gitConfigInit(options) { | ||
await run('git config user.email "you@example.com"', options); | ||
@@ -13,2 +17,5 @@ await run('git config user.name "Your Name"', options); | ||
await run('git config --local core.excludesfile false', options); | ||
}; | ||
} | ||
module.exports = gitInit; | ||
module.exports.gitConfigInit = gitConfigInit; |
@@ -13,3 +13,2 @@ 'use strict'; | ||
const gitInit = require('./git-init'); | ||
const getCheckedOutBranchName = require('./get-checked-out-branch-name'); | ||
const gitStatus = require('./git-status'); | ||
@@ -23,6 +22,5 @@ const commit = require('./commit'); | ||
const createCustomRemote = require('./create-custom-remote'); | ||
const mergeDir = require('./merge-dir'); | ||
const doesBranchExist = require('./does-branch-exist'); | ||
const { isGitClean } = gitStatus; | ||
const { gitConfigInit } = gitInit; | ||
@@ -37,3 +35,3 @@ const tempBranchName = uuidv1(); | ||
module.exports = async function gitDiffApply({ | ||
cwd, | ||
cwd = process.cwd(), | ||
remoteUrl, | ||
@@ -53,14 +51,9 @@ startTag, | ||
let oldBranchName; | ||
let hasConflicts; | ||
let returnObject; | ||
let isTempBranchCheckedOut; | ||
let isCodeUntracked; | ||
let isCodeModified; | ||
let shouldReturnGitIgnoredFiles; | ||
let isTempBranchCommitted; | ||
let root; | ||
let gitIgnoredFiles; | ||
@@ -123,3 +116,3 @@ let err; | ||
async function resetIgnoredFiles() { | ||
async function resetIgnoredFiles(cwd) { | ||
for (let ignoredFile of ignoredFiles) { | ||
@@ -148,3 +141,3 @@ // An exist check is not good enough. | ||
// https://stackoverflow.com/questions/6308625/how-to-avoid-git-apply-changing-line-endings#comment54419617_11189296 | ||
await utils.run(`git apply --whitespace=fix ${patchFile}`, { cwd }); | ||
await utils.run(`git apply --whitespace=fix ${patchFile}`, { cwd: _tmpDir }); | ||
} | ||
@@ -166,3 +159,3 @@ | ||
await resetIgnoredFiles(); | ||
await resetIgnoredFiles(cwd); | ||
@@ -174,19 +167,5 @@ return; | ||
oldBranchName = await getCheckedOutBranchName({ cwd }); | ||
await utils.run(`git checkout --orphan ${tempBranchName}`, { cwd }); | ||
isTempBranchCheckedOut = true; | ||
await utils.run(`git branch ${tempBranchName}`, { cwd: _tmpDir }); | ||
await utils.run(`git checkout ${tempBranchName}`, { cwd: _tmpDir }); | ||
await utils.gitRemoveAll({ cwd: root }); | ||
gitIgnoredFiles = await tmpDir(); | ||
await mergeDir(cwd, gitIgnoredFiles); | ||
shouldReturnGitIgnoredFiles = true; | ||
isCodeUntracked = true; | ||
await copy(); | ||
isTempBranchCommitted = true; | ||
await commit({ cwd }); | ||
isCodeUntracked = false; | ||
let patchFile = await createPatchFile(); | ||
@@ -197,25 +176,16 @@ if (!patchFile) { | ||
isCodeUntracked = true; | ||
isCodeModified = true; | ||
await applyPatch(patchFile); | ||
await resetIgnoredFiles(); | ||
await resetIgnoredFiles(tmpWorkingDir); | ||
let wereAnyChanged = !await isGitClean({ cwd }); | ||
let wereAnyChanged = !await isGitClean({ cwd: _tmpDir }); | ||
if (wereAnyChanged) { | ||
await commit({ cwd }); | ||
} | ||
isCodeUntracked = false; | ||
isCodeModified = false; | ||
await commit({ cwd: _tmpDir }); | ||
let sha; | ||
if (wereAnyChanged) { | ||
sha = await utils.run('git rev-parse HEAD', { cwd }); | ||
} | ||
let sha = await utils.run('git rev-parse HEAD', { cwd: _tmpDir }); | ||
await utils.run(`git checkout ${oldBranchName}`, { cwd }); | ||
isTempBranchCheckedOut = false; | ||
await utils.run(`git remote add ${tempBranchName} ${_tmpDir}`, { cwd }); | ||
await utils.run(`git fetch ${tempBranchName}`, { cwd }); | ||
if (wereAnyChanged) { | ||
try { | ||
@@ -226,2 +196,4 @@ await utils.run(`git cherry-pick --no-commit ${sha.trim()}`, { cwd }); | ||
} | ||
await utils.run(`git remote remove ${tempBranchName}`, { cwd }); | ||
} | ||
@@ -265,2 +237,5 @@ } | ||
// needed because we are going to be committing in here | ||
await gitConfigInit({ cwd: _tmpDir }); | ||
returnObject = await buildReturnObject(); | ||
@@ -297,21 +272,2 @@ | ||
try { | ||
if (isTempBranchCheckedOut) { | ||
await utils.run(`git checkout ${oldBranchName}`, { cwd }); | ||
} | ||
if (isTempBranchCommitted && await doesBranchExist(tempBranchName, { cwd })) { | ||
await utils.run(`git branch -D ${tempBranchName}`, { cwd }); | ||
} | ||
if (shouldReturnGitIgnoredFiles) { | ||
await mergeDir(gitIgnoredFiles, cwd); | ||
} | ||
} catch (err2) { | ||
err = { | ||
err, | ||
err2 | ||
}; | ||
} | ||
if (err) { | ||
@@ -318,0 +274,0 @@ debug('failure'); |
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
6
3
18341
20
495
- Removedklaw@^3.0.0
- Removedklaw@3.0.0(transitive)