# parse-git-patch

> Parse git patches with ease

Latest version **2.1.1** (published 2025-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-git-patch
pnpm add parse-git-patch
yarn add parse-git-patch
bun add parse-git-patch
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2025-01-28 |
| First published | 2020-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | David Hérault |
| Maintainers | dherault |
| Keywords | git, patch, patches, diff, parse, parser |

## Links

- npm: https://www.npmjs.com/package/parse-git-patch
- Repository: https://github.com/dherault/parse-git-patch
- Homepage: https://github.com/dherault/parse-git-patch#readme
- Issues: https://github.com/dherault/parse-git-patch/issues
- npm.io page: https://npm.io/package/parse-git-patch

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2025-01-28
- 2.1.0 — 2025-01-28
- 2.0.1 — 2025-01-27
- 2.0.0 — 2024-11-19
- 1.3.0 — 2024-11-19
- 1.2.2 — 2023-08-03
- 1.2.1 — 2023-08-03
- 1.2.0 — 2023-08-03
- 1.1.1 — 2023-08-03
- 1.1.0 — 2022-10-22
- 1.0.7 — 2020-05-25
- 1.0.6 — 2020-03-28
- 1.0.5 — 2020-03-25
- 1.0.4 — 2020-02-07
- 1.0.3 — 2020-02-03
- … 3 more at https://npm.io/package/parse-git-patch/versions

## README

# parse-git-patch

*Parse git patches with ease*

This NPM package allows you to parse git patches and diffs into an human and machine-readable object.

## Installation

`npm i parse-git-patch`

## Usage

```patch
From 0f6f88c98fff3afa0289f46bf4eab469f45eebc6 Mon Sep 17 00:00:00 2001
From: A dev <a-dev@users.noreply.github.com>
Date: Sat, 25 Jan 2020 19:21:35 +0200
Subject: [PATCH] JSON stringify string responses

---
 src/events/http/HttpServer.js | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js
index 20bf454..c0fdafb 100644
--- a/src/events/http/HttpServer.js
+++ b/src/events/http/HttpServer.js
@@ -770,7 +770,9 @@ export default class HttpServer {
           override: false,
         })

-        if (result && typeof result.body !== 'undefined') {
+        if (typeof result === 'string') {
+          response.source = JSON.stringify(result)
+        } else if (result && typeof result.body !== 'undefined') {
           if (result.isBase64Encoded) {
             response.encoding = 'binary'
             response.source = Buffer.from(result.body, 'base64')
--
2.21.1 (Apple Git-122.3)
```

```js
const parseGitPatch = require('parse-git-patch')

const patch = fs.readFileSync(patchLocation, 'utf-8')
const parsedPatch = parseGitPatch(patch)
```

```js
{
  hash: '0f6f88c98fff3afa0289f46bf4eab469f45eebc6',
  date: 'Sat, 25 Jan 2020 19:21:35 +0200',
  message: '[PATCH] JSON stringify string responses',
  authorEmail: 'a-dev@users.noreply.github.com',
  authorName: 'A dev',
  files: [
    {
      added: false,
      deleted: false,
      beforeName: 'src/events/http/HttpServer.js',
      afterName: 'src/events/http/HttpServer.js',
      modifiedLines: [
        {
          line: '        if (result && typeof result.body !== \'undefined\') {',
          lineNumber: 773,
          added: false,
        },
        {
          line: '        if (typeof result === \'string\') {',
          lineNumber: 773,
          added: true,
        },
        {
          line: '          response.source = JSON.stringify(result)',
          lineNumber: 774,
          added: true,
        },
        {
          line: '        } else if (result && typeof result.body !== \'undefined\') {',
          lineNumber: 775,
          added: true,
        },
      ],
    },
  ],
}
```

## License

MIT

---
_Source: https://npm.io/package/parse-git-patch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
