Skip to content

Commit

Permalink
Handle edge cases in walk diff example (#1622)
Browse files Browse the repository at this point in the history
* Handle edge cases in walk diff example

* Update walk.js

Remove irrelevant code
  • Loading branch information
FossPrime authored Aug 16, 2022
1 parent 24d658c commit 72c14ca
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/api/walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,14 @@ import { join } from '../utils/join.js'
*
* Example 2: Return the difference between the working directory and the HEAD commit
* ```js
* const diff = require('diff-lines')
* async function map(filepath, [head, workdir]) {
* const map = async (filepath, [head, workdir]) => {
* return {
* filepath,
* oid: await head.oid(),
* diff: diff((await head.content()).toString('utf8'), (await workdir.content()).toString('utf8'))
* oid: await head?.oid(),
* diff: diff(
* (await head?.content())?.toString('utf8') || '',
* (await workdir?.content())?.toString('utf8') || ''
* )
* }
* }
* ```
Expand Down

0 comments on commit 72c14ca

Please sign in to comment.