Skip to content

Commit

Permalink
fix(git): handle boundary field in blame
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Dec 18, 2024
1 parent 1182c6e commit 11f59a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git/blame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function blame(path: string, { stdout = "" } = {} as BlameOptions): Blame
tz: Number(porcelain.shift()!.substring("committer-tz ".length)),
},
summary: porcelain.shift()!.substring("summary ".length),
boundary: porcelain[0].startsWith("boundary") ? (porcelain.shift(), true) : false,
previous: porcelain[0].startsWith("previous ") ? porcelain.shift()!.substring("previous ".length) : null,
filename: porcelain.shift()!.substring("filename ".length),
content: porcelain.shift()!.substring(1),
Expand Down Expand Up @@ -62,6 +63,7 @@ export type BlameEntry = {
tz: number
}
summary: string
boundary: boolean
previous: Nullable<string>
filename: string
content: string
Expand Down
13 changes: 13 additions & 0 deletions git/blame_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const expected = [
author: { name: "foo", mail: "<[email protected]>", time: 1, tz: 1 },
committer: { name: "foo", mail: "<[email protected]>", time: 1, tz: 1 },
summary: "feat: initial commit",
boundary: false,
previous: null,
filename: "foo.ts",
content: "console.log('Hello, World!')",
Expand All @@ -16,10 +17,21 @@ const expected = [
author: { name: "bar", mail: "<[email protected]>", time: 2, tz: -1 },
committer: { name: "bar", mail: "<[email protected]>", time: 2, tz: -1 },
summary: "fix: add a comment",
boundary: false,
previous: "a".repeat(40),
filename: "foo.ts",
content: "// Say hello !",
},
{
sha: "c".repeat(40),
author: { name: "qux", mail: "<[email protected]>", time: 3, tz: 0 },
committer: { name: "quux", mail: "<[email protected]>", time: 3, tz: 0 },
summary: "chore: update README",
boundary: true,
previous: null,
filename: "README.md",
content: "# Hello, World!",
},
] as BlameEntry[]

function format(entries: BlameEntry[]) {
Expand All @@ -35,6 +47,7 @@ function format(entries: BlameEntry[]) {
`committer-time ${entry.committer.time}`,
`committer-tz ${entry.committer.tz}`,
`summary ${entry.summary}`,
entry.boundary ? "boundary" : "",
entry.previous ? `previous ${entry.previous}` : "",
`filename ${entry.filename}`,
`\t${entry.content}`,
Expand Down

0 comments on commit 11f59a0

Please sign in to comment.