# Using ts-node
npx ts-node <path/to/git.ts> diff
# Using node
node <path/to/git.js> diffShow changes between index and working tree.
-
First we retrieve the status of files from current working tree using the function
getFileStatus()present in fileStatus.ts. -
Then iterate over the files and create a diff string iteratively. Skip files that are not of out interests.
-
To create the diff for a file, I used the function
createTwoFilesPatch()from the diff package, performed some cleanup and added some text color to match the actualgit diffcommand output. This is handled by the functiondiffFile()present in diff.ts
Note: The output of the original git diff command and the diff command implemented here might be slightly different.