How to use the diff.applyPatches function in diff

To help you get started, we’ve selected a few diff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snyk / snyk / src / lib / protect / apply-patch.js View on Github external
return new Promise((resolve, reject) => {
    diff.applyPatches(patchContent, {
      loadFile: function(index, callback) {
        try {
          const fileName = trimUpToFirstSlash(index.oldFileName);
          if (patchedFiles[fileName]) {
            return callback(null, patchedFiles[fileName]);
          }

          const filePath = path.resolve(relative, fileName);
          const content = fs.readFileSync(filePath, 'utf8');

          // create an `.orig` copy of the file prior to patching it
          // used in case we need to revert a patch
          const origFilePath = filePath + '.orig';
          fs.writeFileSync(origFilePath, content);

          callback(null, content);
github eclipse / orion.client / modules / orionode / lib / git / diff.js View on Github external
function apply() {
				var failed = [], successed = [];
				mDiff.applyPatches(file, {
					getUnprefixFile: function(f) {
						return f.split("/").slice(1).join("/");
					},
					getFile: function(f) {
						return path.join(repo.workdir(), this.getUnprefixFile(f));
					},
					loadFile: function(index, cb) {
						if (!index.oldFileName) {
							return cb({message: "Patch is not valid: missing old file name."});
						}
						if (index.oldFileName === "/dev/null") {
							return cb(null, "");
						}
						fs.readFile(this.getFile(index.oldFileName), "utf8", cb);
					},
					patched: function(index, content, cb) {