From 222f0c8e1f92537259d3c478fb9fed36029014c1 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Sun, 29 Mar 2026 11:51:50 -0400 Subject: [PATCH 1/7] init for PR --- package-lock.json | 4 ++-- package.json | 2 +- src/command/auth.ts | 2 ++ src/extension.ts | 2 +- src/sync/git.ts | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6693504..91faed1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "settings-repository", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "settings-repository", - "version": "2.0.1", + "version": "2.0.2", "license": "GPL-2.0-only", "devDependencies": { "@types/adm-zip": "0.5.7", diff --git a/package.json b/package.json index 373a073..beb0d85 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "theme": "dark" }, "publisher": "Katsute", - "version": "2.0.1", + "version": "2.0.2", "private": true, "engines": { "vscode": "^1.109.0" diff --git a/src/command/auth.ts b/src/command/auth.ts index 6c176de..c866fb0 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -81,6 +81,8 @@ export const authenticate: () => void = () => { }).then((password?: string) => { if(!password) return; + // TODO: test credentials + const dist: Distribution = extension.distribution(); logger.info(`Updated authentication: ${username}`); diff --git a/src/extension.ts b/src/extension.ts index 3cc3266..a678889 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -68,7 +68,7 @@ export const activate: (context: vscode.ExtensionContext) => void = (context: vs logger.debug(`branch: ${config.get("branch")}`); logger.debug(`autoSync: ${config.get("autoSync")}`); logger.debug(`includeHostnameInCommitMessage: ${config.get("includeHostnameInCommitMessage")}`); - logger.debug(`authenticated: ${!!auth.authorization()}`); + logger.debug(`has credentials: ${!!auth.authorization()}`); if(config.get("autoSync") === true && config.get("autoSyncMode") !== "Export Only") config.get("repository") && pull(config.get("repository"), true); diff --git a/src/sync/git.ts b/src/sync/git.ts index 09dd2ca..d53ad65 100644 --- a/src/sync/git.ts +++ b/src/sync/git.ts @@ -156,7 +156,7 @@ export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: s } }); }catch(error: any){ - logger.error(`Push failed: ${auth.mask(error, cred)}`, true); + logger.error(`Pull failed: ${auth.mask(error, cred)}`, true); }finally{ cleanup(temp); } From a5fc7f3812e96d819b1a5dbd4ec7a75607a687bf Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Sun, 29 Mar 2026 12:35:57 -0400 Subject: [PATCH 2/7] test credentials on submit --- src/command/auth.ts | 35 ++++++++++++++++++++++++++++------- src/command/local.ts | 2 +- src/command/remote.ts | 2 +- src/extension.ts | 4 ++-- src/sync/git.ts | 22 +++++++++------------- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/command/auth.ts b/src/command/auth.ts index c866fb0..a46597c 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -22,12 +22,15 @@ import * as fs from "fs"; import * as os from "os"; import { isNull, isValidJson } from "../lib/is"; +import * as config from "../config"; import * as logger from "../logger"; import * as files from "../lib/files"; +import * as git from "../sync/git"; import { Crypt } from "../lib/encrypt"; import * as extension from "../extension"; import { Distribution } from "../distribution"; import { CommandQuickPickItem } from "../lib/quickpick"; +import simpleGit from "simple-git"; // @@ -78,22 +81,40 @@ export const authenticate: () => void = () => { if(value.trim().length === 0) return "Token can not be blank"; } - }).then((password?: string) => { + }).then(async (password?: string) => { if(!password) return; - // TODO: test credentials + const repo: string = config.get("repository"); - const dist: Distribution = extension.distribution(); + if(repo){ + const cred: credentials = { login: username, auth: password }; + const remote: string = git.parseRepo(repo, cred); - logger.info(`Updated authentication: ${username}`); + const err = await simpleGit().listRemote([remote]) + .then(() => { + logger.info(`Credentials are valid for ${repo}`); + return null; + }) + .catch(e => { + logger.error(`Failed to verify credentials for ${repo}:\n ${mask(e.message, cred)}`); + vscode.window.showErrorMessage("Failed to authenticate with provided credentials, please check your username and token and try again."); + return e; + }); - fs.writeFileSync( - dist.credentials, + if(!err){ + const dist: Distribution = extension.distribution(); + + logger.info(`Updated authentication: ${username}`); + + fs.writeFileSync( + dist.credentials, `{ "login": "${username}", "auth": "${crypt.encrypt(password)}" }`, - "utf-8"); + "utf-8"); + } + } }); }); } diff --git a/src/command/local.ts b/src/command/local.ts index 57f5cdf..2cc3a38 100644 --- a/src/command/local.ts +++ b/src/command/local.ts @@ -31,5 +31,5 @@ export const item: CommandQuickPickItem = { } export const command: vscode.Disposable = vscode.commands.registerCommand("settings-repository.overwriteLocal", () => { - config.get("repository") && pull(config.get("repository")); + config.get("repository") && pull(config.get("repository"), config.get("branch")); }); \ No newline at end of file diff --git a/src/command/remote.ts b/src/command/remote.ts index be81f2b..c300ce0 100644 --- a/src/command/remote.ts +++ b/src/command/remote.ts @@ -31,5 +31,5 @@ export const item: CommandQuickPickItem = { } export const command: vscode.Disposable = vscode.commands.registerCommand("settings-repository.overwriteRemote", () => { - config.get("repository") && push(config.get("repository")); + config.get("repository") && push(config.get("repository"), config.get("branch")); }); \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index a678889..ecd6423 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -71,13 +71,13 @@ export const activate: (context: vscode.ExtensionContext) => void = (context: vs logger.debug(`has credentials: ${!!auth.authorization()}`); if(config.get("autoSync") === true && config.get("autoSyncMode") !== "Export Only") - config.get("repository") && pull(config.get("repository"), true); + config.get("repository") && pull(config.get("repository"), config.get("branch"), true); } // must be async, otherwise vscode closes without waiting export const deactivate: () => Promise = async () => { if(config.get("autoSync") === true && config.get("autoSyncMode") !== "Import Only") - config.get("repository") && await push(config.get("repository"), true); + config.get("repository") && await push(config.get("repository"), config.get("branch"), true); } export const notify: () => void = () => { diff --git a/src/sync/git.ts b/src/sync/git.ts index d53ad65..136eba7 100644 --- a/src/sync/git.ts +++ b/src/sync/git.ts @@ -42,12 +42,12 @@ const cleanup: (fsPath: string) => void = (fsPath: string) => { statusbar.setActive(false); }; -const parseRepo: (repo: string, cred: auth.credentials) => string = (repo: string, cred: auth.credentials) => { +export const parseRepo: (repo: string, cred: auth.credentials) => string = (repo: string, cred: auth.credentials) => { const part: string[] = repo.split("://"); return `${part[0]}://${cred.login}:${cred.auth}@${part.slice(1).join("://")}`; } -export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: string, skipNotify: boolean = false) => { +export const pull: (repo: string, branch: string, skipNotify?: boolean) => void = async (repo: string, branch: string = "main", skipNotify: boolean = false) => { if(isNull(repo)) return; const dist: Distribution = extension.distribution(); @@ -65,13 +65,11 @@ export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: s const remote: string = parseRepo(repo, cred); - const branch: string = config.get("branch") ?? "main"; - // callback const gitback: (err: GitError | null) => void = (err: GitError | null) => { if(err){ - logger.error(`Failed to pull from ${config.get("repository")}:\n ${auth.mask(err.message, cred)}`, true); + logger.error(`Failed to pull from ${repo}@${branch}:\n ${auth.mask(err.message, cred)}`); cleanup(temp); } }; @@ -80,7 +78,7 @@ export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: s statusbar.setActive(true); - logger.info(`Preparing to import settings from ${config.get("repository")}@${branch}`); + logger.info(`Preparing to import settings from ${repo}@${branch}`); logger.debug(`Git clone ${auth.mask(remote, cred)}`); // forced delay so git repo can get up-to-date after a fast reload/restart @@ -148,7 +146,7 @@ export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: s logger.warn("Snippets not found"); } - logger.info(`Imported settings from ${config.get("repository")}@${branch}`, true); + logger.info(`Imported settings from ${repo}@${branch}`, true); cleanup(temp); @@ -162,7 +160,7 @@ export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: s } } -export const push: (repo: string, ignoreBadAuth?: boolean) => Promise = async (repo: string, ignoreBadAuth: boolean = false) => { +export const push: (repo: string, branch: string, ignoreBadAuth?: boolean) => Promise = async (repo: string, branch: string = "main", ignoreBadAuth: boolean = false) => { if(isNull(repo)) return; const dist: Distribution = extension.distribution(); @@ -180,13 +178,11 @@ export const push: (repo: string, ignoreBadAuth?: boolean) => Promise = as const remote: string = parseRepo(repo, cred); - const branch: string = config.get("branch") ?? "main"; - // callback const gitback: (err: GitError | null) => void = (err: GitError | null) => { if(err){ - logger.error(`Failed to push to ${config.get("repository")}:\n ${auth.mask(err.message, cred)}`, true); + logger.error(`Failed to push to ${repo}@${branch}:\n ${auth.mask(err.message, cred)}`, true); cleanup(temp); } }; @@ -195,7 +191,7 @@ export const push: (repo: string, ignoreBadAuth?: boolean) => Promise = as statusbar.setActive(true); - logger.info(`Preparing to export settings to ${config.get("repository")}@${branch}`); + logger.info(`Preparing to export settings to ${repo}@${branch}`); logger.debug(`Git clone ${auth.mask(remote, cred)}`); logger.debug(`includeHostnameInCommit: ${config.get("includeHostnameInCommitMessage")}`); @@ -271,7 +267,7 @@ export const push: (repo: string, ignoreBadAuth?: boolean) => Promise = as .push(["-u", "origin", "HEAD"], (err: GitError | null) => { gitback(err); if(!err){ - logger.info(`Pushed settings to ${config.get("repository")}@${branch}`, true); + logger.info(`Pushed settings to ${repo}@${branch}`, true); cleanup(temp); } }); From 3d33ec2ca2cebf2ac731d9fd2882c5ef69fc19d9 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Sun, 29 Mar 2026 20:08:00 -0400 Subject: [PATCH 3/7] fixes --- src/command/auth.ts | 16 +++++++--------- src/sync/git.ts | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/command/auth.ts b/src/command/auth.ts index a46597c..baefc8c 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -90,7 +90,7 @@ export const authenticate: () => void = () => { const cred: credentials = { login: username, auth: password }; const remote: string = git.parseRepo(repo, cred); - const err = await simpleGit().listRemote([remote]) + await simpleGit().listRemote([remote]) .then(() => { logger.info(`Credentials are valid for ${repo}`); return null; @@ -100,21 +100,19 @@ export const authenticate: () => void = () => { vscode.window.showErrorMessage("Failed to authenticate with provided credentials, please check your username and token and try again."); return e; }); + } - if(!err){ - const dist: Distribution = extension.distribution(); + const dist: Distribution = extension.distribution(); - logger.info(`Updated authentication: ${username}`); + logger.info(`Updated authentication: ${username}`); - fs.writeFileSync( - dist.credentials, + fs.writeFileSync( + dist.credentials, `{ "login": "${username}", "auth": "${crypt.encrypt(password)}" }`, - "utf-8"); - } - } + "utf-8"); }); }); } diff --git a/src/sync/git.ts b/src/sync/git.ts index 136eba7..d2919e9 100644 --- a/src/sync/git.ts +++ b/src/sync/git.ts @@ -47,13 +47,13 @@ export const parseRepo: (repo: string, cred: auth.credentials) => string = (repo return `${part[0]}://${cred.login}:${cred.auth}@${part.slice(1).join("://")}`; } -export const pull: (repo: string, branch: string, skipNotify?: boolean) => void = async (repo: string, branch: string = "main", skipNotify: boolean = false) => { +export const pull: (repo: string, branch?: string, skipNotify?: boolean) => Promise = async (repo: string, branch: string = "main", skipNotify: boolean = false) => { if(isNull(repo)) return; const dist: Distribution = extension.distribution(); const cred: auth.credentials | undefined = auth.authorization(); - if(!cred) return skipNotify || auth.authenticate(); + if(!cred) return (skipNotify || auth.authenticate()) as void; // init directory @@ -69,7 +69,7 @@ export const pull: (repo: string, branch: string, skipNotify?: boolean) => void const gitback: (err: GitError | null) => void = (err: GitError | null) => { if(err){ - logger.error(`Failed to pull from ${repo}@${branch}:\n ${auth.mask(err.message, cred)}`); + logger.error(`Failed to pull from ${repo}@${branch}:\n ${auth.mask(err.message, cred)}`, true); cleanup(temp); } }; From b5c259419ef407d62b4f91933ca065ba34db4e7b Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Sun, 29 Mar 2026 20:18:01 -0400 Subject: [PATCH 4/7] simplify --- src/command/auth.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/command/auth.ts b/src/command/auth.ts index baefc8c..9d4f2b8 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -93,12 +93,9 @@ export const authenticate: () => void = () => { await simpleGit().listRemote([remote]) .then(() => { logger.info(`Credentials are valid for ${repo}`); - return null; }) .catch(e => { - logger.error(`Failed to verify credentials for ${repo}:\n ${mask(e.message, cred)}`); - vscode.window.showErrorMessage("Failed to authenticate with provided credentials, please check your username and token and try again."); - return e; + logger.error(`Failed to verify credentials for ${repo}:\n ${mask(e.message, cred)}`, true); }); } From f7013712b2ced1bb2370c954ae0aec5f5125e95e Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Sun, 29 Mar 2026 20:18:26 -0400 Subject: [PATCH 5/7] syntax --- src/command/auth.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/command/auth.ts b/src/command/auth.ts index 9d4f2b8..ddab3bd 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -109,7 +109,8 @@ export const authenticate: () => void = () => { "login": "${username}", "auth": "${crypt.encrypt(password)}" }`, - "utf-8"); + "utf-8" + ); }); }); } From 6c07a9ee27835506274f6b101c9a89c8d020cffa Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Tue, 31 Mar 2026 21:11:06 -0400 Subject: [PATCH 6/7] fixes --- src/command/auth.ts | 5 ++++- src/sync/git.ts | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/command/auth.ts b/src/command/auth.ts index ddab3bd..a7872a4 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -90,13 +90,16 @@ export const authenticate: () => void = () => { const cred: credentials = { login: username, auth: password }; const remote: string = git.parseRepo(repo, cred); - await simpleGit().listRemote([remote]) + const err = await simpleGit().listRemote([remote]) .then(() => { logger.info(`Credentials are valid for ${repo}`); }) .catch(e => { logger.error(`Failed to verify credentials for ${repo}:\n ${mask(e.message, cred)}`, true); + return e; }); + + if(err) return; } const dist: Distribution = extension.distribution(); diff --git a/src/sync/git.ts b/src/sync/git.ts index d2919e9..8102e16 100644 --- a/src/sync/git.ts +++ b/src/sync/git.ts @@ -53,7 +53,10 @@ export const pull: (repo: string, branch?: string, skipNotify?: boolean) => Prom const dist: Distribution = extension.distribution(); const cred: auth.credentials | undefined = auth.authorization(); - if(!cred) return (skipNotify || auth.authenticate()) as void; + if(!cred) { + skipNotify || auth.authenticate(); + return; + } // init directory @@ -154,13 +157,13 @@ export const pull: (repo: string, branch?: string, skipNotify?: boolean) => Prom } }); }catch(error: any){ - logger.error(`Pull failed: ${auth.mask(error, cred)}`, true); + logger.error(`Pull failed: ${auth.mask(String(error?.message ?? error), cred)}`, true); }finally{ cleanup(temp); } } -export const push: (repo: string, branch: string, ignoreBadAuth?: boolean) => Promise = async (repo: string, branch: string = "main", ignoreBadAuth: boolean = false) => { +export const push: (repo: string, branch?: string, ignoreBadAuth?: boolean) => Promise = async (repo: string, branch: string = "main", ignoreBadAuth: boolean = false) => { if(isNull(repo)) return; const dist: Distribution = extension.distribution(); @@ -253,7 +256,7 @@ export const push: (repo: string, branch: string, ignoreBadAuth?: boolean) => Pr } }catch(error: any){ if(error){ - logger.error(`Push failed: ${auth.mask(error, cred)}`, true); + logger.error(`Push failed: ${auth.mask(String(error), cred)}`, true); cleanup(temp); } } @@ -272,7 +275,7 @@ export const push: (repo: string, branch: string, ignoreBadAuth?: boolean) => Pr } }); }catch(error: any){ - logger.error(`Push failed: ${auth.mask(error, cred)}`, true); + logger.error(`Push failed: ${auth.mask(String(error?.message ?? error), cred)}`, true); }finally{ cleanup(temp); } From b1a3874c7eedf9b44908844dd5b08e8907071efb Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Tue, 31 Mar 2026 21:22:25 -0400 Subject: [PATCH 7/7] fixes --- src/command/auth.ts | 10 +++++++--- src/sync/git.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/command/auth.ts b/src/command/auth.ts index a7872a4..687a935 100644 --- a/src/command/auth.ts +++ b/src/command/auth.ts @@ -25,7 +25,6 @@ import { isNull, isValidJson } from "../lib/is"; import * as config from "../config"; import * as logger from "../logger"; import * as files from "../lib/files"; -import * as git from "../sync/git"; import { Crypt } from "../lib/encrypt"; import * as extension from "../extension"; import { Distribution } from "../distribution"; @@ -55,6 +54,11 @@ const crypt: Crypt = new Crypt(os.hostname()); // +const parseRepo: (repo: string, cred: credentials) => string = (repo: string, cred: credentials) => { + const part: string[] = repo.split("://"); + return `${part[0]}://${cred.login}:${cred.auth}@${part.slice(1).join("://")}`; +} + export const mask: (s: string, c: credentials) => string = (s: string, c: credentials) => { return s.replace(new RegExp(c.auth, "gm"), "***"); } @@ -88,14 +92,14 @@ export const authenticate: () => void = () => { if(repo){ const cred: credentials = { login: username, auth: password }; - const remote: string = git.parseRepo(repo, cred); + const remote: string = parseRepo(repo, cred); const err = await simpleGit().listRemote([remote]) .then(() => { logger.info(`Credentials are valid for ${repo}`); }) .catch(e => { - logger.error(`Failed to verify credentials for ${repo}:\n ${mask(e.message, cred)}`, true); + logger.error(`Failed to verify credentials for ${repo}:\n ${mask(String(e?.message ?? e), cred)}`, true); return e; }); diff --git a/src/sync/git.ts b/src/sync/git.ts index 8102e16..aebd4e6 100644 --- a/src/sync/git.ts +++ b/src/sync/git.ts @@ -42,7 +42,7 @@ const cleanup: (fsPath: string) => void = (fsPath: string) => { statusbar.setActive(false); }; -export const parseRepo: (repo: string, cred: auth.credentials) => string = (repo: string, cred: auth.credentials) => { +const parseRepo: (repo: string, cred: auth.credentials) => string = (repo: string, cred: auth.credentials) => { const part: string[] = repo.split("://"); return `${part[0]}://${cred.login}:${cred.auth}@${part.slice(1).join("://")}`; }