aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-18 14:06:32 +0200
committerHampusM <hampus@hampusmat.com>2021-07-18 14:06:32 +0200
commit9684e2dec933f1be80543748f1753761006c3d5f (patch)
tree2d5fcc0d79dd948ffdfab208e8003b83967e6e26
parent2e333f01de88217f33ed2fb9ba0c18ed1357419c (diff)
Fixed the bug caused by inproper handling of empty patches
-rw-r--r--README.md2
-rw-r--r--packages/client/src/components/CommitPatch.vue6
-rw-r--r--packages/server/src/git/patch.ts8
3 files changed, 13 insertions, 3 deletions
diff --git a/README.md b/README.md
index d934ccd..3e0f853 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ Githermit requires no such thing. All the steps to get it set up are in [Usage](
- [x] Blob page
- [x] Markdown support
- [ ] Tests
-- [ ] Fix the stupid bug caused by empty patches
+- [x] Fix the stupid bug caused by empty patches
- [ ] Branch switching
- [x] Custom favicon support
- [x] Custom website title support
diff --git a/packages/client/src/components/CommitPatch.vue b/packages/client/src/components/CommitPatch.vue
index dca886f..fbc9e3a 100644
--- a/packages/client/src/components/CommitPatch.vue
+++ b/packages/client/src/components/CommitPatch.vue
@@ -19,6 +19,12 @@ export default defineComponent({
]);
}
+ if(!props.patch.hunks) {
+ return () => h("div", { class: "ps-3 pt-3" }, [
+ h("span", "Empty.")
+ ]);
+ }
+
// Array of hunks without the first chunk headers
const all_hunks = props.patch.hunks.map((hunk) => hunk.hunk.split("\n").slice(1).join("\n"));
diff --git a/packages/server/src/git/patch.ts b/packages/server/src/git/patch.ts
index 126b203..f7eb88e 100644
--- a/packages/server/src/git/patch.ts
+++ b/packages/server/src/git/patch.ts
@@ -89,10 +89,14 @@ export class Patch {
return false;
}
- public async getHunks(index: number): Promise<Hunk[] | null> {
- const content = (await this.content(index)).split("\n");
+ public async getHunks(patch_index: number): Promise<Hunk[] | null> {
+ const content = (await this.content(patch_index)).split("\n");
const hunks = await this._ng_patch.hunks();
+ if(hunks.length === 0) {
+ return null;
+ }
+
const hunks_data = hunks.reduce((result: Hunks, hunk, hunk_index) => {
const hunk_header = hunk.header();
const hunk_header_index = content.indexOf(hunk_header.replace(/\n/gu, ""));