* adding branch support * gitsync settings refactor * promotionOverride * require branches and initialize them * branches -> git_branches * profiles * format * format * only warn instead of error when branches: not set in git context * error handling * formatting * modal job handling improvement * respect --yes * logging + apply effective settings * nit * ui updates * npm check * Update frontend/src/lib/components/git_sync/PullWorkspaceModal.svelte Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * hubpaths --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { log } from "../../deps.ts";
|
|
import { getStore } from "./store.ts";
|
|
|
|
export interface BranchProfileMapping {
|
|
lastUsed: {
|
|
[key: string]: string; // key format: "branch|baseUrl|workspaceId" -> profile name
|
|
};
|
|
}
|
|
|
|
const BRANCH_PROFILES_FILE = "branch-profiles.json";
|
|
|
|
export async function getBranchProfilesPath(configDirOverride?: string): Promise<string> {
|
|
return (await getStore("", configDirOverride)) + BRANCH_PROFILES_FILE;
|
|
}
|
|
|
|
export async function loadBranchProfiles(configDirOverride?: string): Promise<BranchProfileMapping> {
|
|
try {
|
|
const path = await getBranchProfilesPath(configDirOverride);
|
|
const content = await Deno.readTextFile(path);
|
|
return JSON.parse(content);
|
|
} catch {
|
|
// File doesn't exist or invalid JSON - return empty mapping
|
|
return { lastUsed: {} };
|
|
}
|
|
}
|
|
|
|
export async function saveBranchProfiles(
|
|
mapping: BranchProfileMapping,
|
|
configDirOverride?: string
|
|
): Promise<void> {
|
|
const path = await getBranchProfilesPath(configDirOverride);
|
|
await Deno.writeTextFile(path, JSON.stringify(mapping, null, 2));
|
|
}
|
|
|
|
export function getBranchProfileKey(
|
|
branch: string,
|
|
baseUrl: string,
|
|
workspaceId: string
|
|
): string {
|
|
// Normalize baseUrl to ensure consistency
|
|
let normalizedUrl: string;
|
|
try {
|
|
normalizedUrl = new URL(baseUrl).toString();
|
|
} catch {
|
|
// Fallback to non-normalized URL if parsing fails
|
|
normalizedUrl = baseUrl;
|
|
}
|
|
return `${branch}|${normalizedUrl}|${workspaceId}`;
|
|
}
|
|
|
|
export async function getLastUsedProfile(
|
|
branch: string,
|
|
baseUrl: string,
|
|
workspaceId: string,
|
|
configDirOverride?: string
|
|
): Promise<string | undefined> {
|
|
const mapping = await loadBranchProfiles(configDirOverride);
|
|
const key = getBranchProfileKey(branch, baseUrl, workspaceId);
|
|
return mapping.lastUsed[key];
|
|
}
|
|
|
|
export async function setLastUsedProfile(
|
|
branch: string,
|
|
baseUrl: string,
|
|
workspaceId: string,
|
|
profileName: string,
|
|
configDirOverride?: string
|
|
): Promise<void> {
|
|
const mapping = await loadBranchProfiles(configDirOverride);
|
|
const key = getBranchProfileKey(branch, baseUrl, workspaceId);
|
|
mapping.lastUsed[key] = profileName;
|
|
await saveBranchProfiles(mapping, configDirOverride);
|
|
log.debug(`Saved last used profile for ${key}: ${profileName}`);
|
|
}
|