From 85efad5750394b5cbf132c9cc2d8b7aa12f0c8a4 Mon Sep 17 00:00:00 2001
From: Maddy Guthridge
Date: Sun, 15 Sep 2024 16:59:09 +1000
Subject: [PATCH] Implement git status display
---
src/lib/server/git.ts | 4 ++-
src/routes/admin/+page.svelte | 47 +++++++++++++++++++++++++++++++++--
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/src/lib/server/git.ts b/src/lib/server/git.ts
index e5456bb0..6395a6b4 100644
--- a/src/lib/server/git.ts
+++ b/src/lib/server/git.ts
@@ -43,7 +43,9 @@ export async function getRepoStatus(): Promise {
clean: status.isClean(),
ahead: status.ahead,
behind: status.behind,
- changes: status.files,
+ // Need to map changed files to a new object or we get a JSON serialize
+ // error
+ changes: status.files.map(f => ({ ...f })),
};
}
diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte
index b02ba196..ebdc403b 100644
--- a/src/routes/admin/+page.svelte
+++ b/src/routes/admin/+page.svelte
@@ -9,6 +9,17 @@
// Git setup
let gitUrl = '';
+
+ async function submitSwitchToGit() {
+ await api().admin.git.init(gitUrl);
+ }
+
+ // Git controls
+ let commitMessage = '';
+
+ async function gitCommit() {
+ await api().admin.git.commit(commitMessage);
+ }
@@ -45,14 +56,46 @@
{/if}
+
+ {#if data.repo.behind}
+
+ {:else if data.repo.ahead}
+
+ {/if}
+
+
+ {#if !data.repo.clean}
+
+ Changes
+
+
+ {#each data.repo.changes as change}
+ {#if change.from}
+ - Rename {change.from} to ({change.path})
+ {:else if change.index === '?'}
+ - Create {change.path}
+ {:else if change.index === 'D'}
+ - Delete {change.path}
+ {:else}
+ - Update {change.path}
+ {/if}
+ {/each}
+
+
+
+ {/if}
+
{:else}
Git is currently not in use
You can use a Git repository to back up your portfolio data. Enter the
clone URL for an empty Git repository and it will be set up for you.
-
{/if}