Skip to content

Commit

Permalink
fix: getUnifiedDiff() returns diff
Browse files Browse the repository at this point in the history
  • Loading branch information
kometenstaub committed Mar 11, 2022
1 parent 1d6b2fe commit 6d6b021
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/diff_utils.ts
Expand Up @@ -35,19 +35,22 @@ export default class DiffUtils {
// Thank you: https://github.com/marcusolsson/obsidian-vale/blob/fdc0fc5d1c259cc823b867ae2d278f09703acf43/src/vale/ValeCli.ts#L12
async getUnifiedDiff(str1: string, str2: string): Promise<string | void> {
// 5 is currently the amount of context
const child = exec(
`diff -u5 <(echo -e "${str1}") <(echo -e "${str2}")`,
(error, stdout, stderr) => {
if (stdout) {
console.log(stdout);
return stdout;
} else if (error) {
console.error(`exec error: ${error}`);
return;
} else if (stderr) {
console.error(`stderr: ${stderr}`);
return new Promise((resolve, reject) => {
exec(
`diff -u5 <(echo -e "${str1}") <(echo -e "${str2}")`,
(error, stdout, stderr) => {
if (stdout) {
//console.log(stdout);
resolve(stdout)
} else if (error) {
console.error(`exec error: ${error}`);
reject(error);
} else if (stderr) {
console.error(`stderr: ${stderr}`);
reject(stderr)
}
}
}
);
);
})
}
}

0 comments on commit 6d6b021

Please sign in to comment.