I'm currently using the Simple Git library in my Node.js project to get the diff of a specific file. However, when I use the git.diff(["--"], file) function, it returns the entire diff instead of the diff for the specific file. Here's the code snippet:
GitControl.prototype.diff = async function (git, param, callback) {
const file = param[0];
console.log(file);
try {
const result = await git.diff(["--"], file);
callback(null, JSON.stringify({ success: true, diffText: result }));
} catch (err) {
console.log(`GIT CONTROL DIFF ERROR OCCUR: ${err}`);
callback(err, JSON.stringify({ success: false, error: err.message }));
}
};
When I run the equivalent command in the terminal (git diff -- bin/Source/MainView.js), it works as expected and returns the diff for the specified file.
I've confirmed that the file variable contains the correct file path (e.g., "bin/Source/View/qnaView.js").
Is there a difference between the git diff -- command in the terminal and the git.diff(["--"], file) function in Simple Git? If so, how can I modify my code to get the diff for a specific file?
const result = await git.diff(["--", file]);
simply solved