Add local repository scanning and UI
Implement local repository scanning end-to-end. Frontend: add UI (toolbar, local-scan panel, list/cards), CSS styles, icons, new state fields, and templates; convert recent repo items to buttons and wire up actions to select, view and open scanned repos. JS: add helper utilities (repoNameFromPath, normalizeRemoteUrl, serverRepoRemoteUrls), scanForLocalRepos/selectLocalRepo functions, render template for scan results, and call scanLocalRepos via tauri-api. Tauri API: expose scan_local_repos (tauri command) in tauri-api.js. Backend (Rust): add LocalRepoCandidate type and a scanner implementation that walks configurable/default roots, deduplicates paths, matches local remotes against allowed server URLs, enforces depth/result limits, and returns matched candidates; register scan_local_repos in the command list. Includes error handling and user-facing messages for missing roots or remotes.
This commit is contained in:
+158
-8
@@ -338,17 +338,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.recent-item {
|
.recent-item {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
border: 0;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: transparent;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
padding: 4px 0;
|
padding: 4px 6px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.recent-item:hover {
|
.recent-item:hover {
|
||||||
|
background: var(--bg-hover);
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
|
border: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Git output ───────────────────────────────────── */
|
/* ── Git output ───────────────────────────────────── */
|
||||||
@@ -380,15 +388,157 @@
|
|||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Local repo indicator ─────────────────────────── */
|
/* ── GitHub Desktop style toolbar ─────────────────── */
|
||||||
.selected-repo {
|
.gd-toolbar {
|
||||||
font-size: 13px;
|
display: grid;
|
||||||
padding: 6px 10px;
|
grid-template-columns: minmax(0, 2fr) minmax(0, 1.5fr) minmax(0, 1.5fr);
|
||||||
background: rgba(47, 129, 247, 0.06);
|
align-items: stretch;
|
||||||
border: 1px solid rgba(47, 129, 247, 0.2);
|
width: 100%;
|
||||||
|
height: 56px;
|
||||||
|
margin: -16px -16px 16px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: var(--bg-panel);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main > .gd-toolbar {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
border-radius: var(--radius-md);
|
border-radius: var(--radius-md);
|
||||||
word-break: break-all;
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-toolbar-cell {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0 14px;
|
||||||
|
border: 0;
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
border-radius: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--text-main);
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: left;
|
||||||
|
transition: background 0.1s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-toolbar-cell:last-child {
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-toolbar-cell:hover:not(:disabled):not(.gd-toolbar-cell-empty) {
|
||||||
|
background: rgba(177, 186, 196, 0.08);
|
||||||
|
border-color: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-toolbar-cell:disabled,
|
||||||
|
.gd-toolbar-cell-empty {
|
||||||
|
cursor: default;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-cell-icon {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-cell-copy {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-cell-label {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-cell-value {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-main);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-cell-value-muted {
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gd-cell-caret {
|
||||||
|
color: var(--text-muted);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-repo-path-line {
|
||||||
|
margin-top: -6px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: ui-monospace, "Cascadia Code", "Fira Code", Consolas, monospace;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-scan-panel {
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
background: rgba(33, 38, 45, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-scan-title {
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-repo-list {
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
max-height: 320px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-repo-card {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
background: var(--bg-panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-repo-info {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-repo-info span {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.local-scan-empty {
|
||||||
|
padding: 24px 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Empty state ──────────────────────────────────── */
|
/* ── Empty state ──────────────────────────────────── */
|
||||||
|
|||||||
+211
-18
@@ -9,6 +9,7 @@ import {
|
|||||||
runGitPull,
|
runGitPull,
|
||||||
runGitPush,
|
runGitPush,
|
||||||
runGitStatus,
|
runGitStatus,
|
||||||
|
scanLocalRepos,
|
||||||
testGiteaConnection,
|
testGiteaConnection,
|
||||||
} from "./tauri-api.js";
|
} from "./tauri-api.js";
|
||||||
|
|
||||||
@@ -34,6 +35,9 @@ const maxPreviewBytes = 256 * 1024;
|
|||||||
|
|
||||||
const FOLDER_ICON = `<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill="#54aeff" d="M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"/></svg>`;
|
const FOLDER_ICON = `<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill="#54aeff" d="M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"/></svg>`;
|
||||||
const FILE_ICON = `<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill="#848d97" d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"/></svg>`;
|
const FILE_ICON = `<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill="#848d97" d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"/></svg>`;
|
||||||
|
const LOCAL_REPO_ICON = `<svg width="20" height="20" viewBox="0 0 16 16" aria-hidden="true" fill="none"><rect x="1.5" y="3" width="13" height="8.5" rx="1.25" stroke="currentColor" stroke-width="1.3"/><path d="M6 13.75h4M8 11.5v2.25" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg>`;
|
||||||
|
const BRANCH_ICON = `<svg width="18" height="18" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"/></svg>`;
|
||||||
|
const SYNC_ICON = `<svg width="18" height="18" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 2.5a5.487 5.487 0 0 0-4.131 1.869l1.204 1.204A.25.25 0 0 1 4.896 6H1.25A.25.25 0 0 1 1 5.75V2.104a.25.25 0 0 1 .427-.177l1.38 1.38A7 7 0 0 1 14.95 7.16a.75.75 0 1 1-1.49.178A5.501 5.501 0 0 0 8 2.5ZM1.705 8.005a.75.75 0 0 1 .834.656 5.501 5.501 0 0 0 9.592 2.97l-1.204-1.204a.25.25 0 0 1 .177-.427h3.646a.25.25 0 0 1 .25.25v3.646a.25.25 0 0 1-.427.177l-1.38-1.38A7 7 0 0 1 1.05 8.84a.75.75 0 0 1 .656-.834Z"/></svg>`;
|
||||||
|
|
||||||
function uid() {
|
function uid() {
|
||||||
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||||
@@ -60,6 +64,24 @@ function parentPath(path = "") {
|
|||||||
return parts.join("/");
|
return parts.join("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function repoNameFromPath(path = "") {
|
||||||
|
return path.split(/[/\\]/).filter(Boolean).pop() || path;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeRemoteUrl(value = "") {
|
||||||
|
return value.trim().replace(/\/+$/, "").replace(/\.git$/i, "").toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function serverRepoRemoteUrls() {
|
||||||
|
const urls = repositories.flatMap((repo) => [
|
||||||
|
repo.clone_url,
|
||||||
|
repo.ssh_url,
|
||||||
|
repo.html_url,
|
||||||
|
repo.original_url,
|
||||||
|
]);
|
||||||
|
return [...new Set(urls.map((url) => normalizeRemoteUrl(url || "")).filter(Boolean))];
|
||||||
|
}
|
||||||
|
|
||||||
function languageForPath(path = "") {
|
function languageForPath(path = "") {
|
||||||
const extension = path.split(".").pop()?.toLowerCase();
|
const extension = path.split(".").pop()?.toLowerCase();
|
||||||
const names = {
|
const names = {
|
||||||
@@ -383,6 +405,46 @@ function repoCardTemplate(repo) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function localRepoScanTemplate() {
|
||||||
|
const state = getState();
|
||||||
|
const results = state.localRepoScanResults || [];
|
||||||
|
|
||||||
|
if (state.localRepoScanLoading) {
|
||||||
|
return `<div class="viewer-loading">Scanning local folders for repositories from the selected Gitea server...</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.localRepoScanError) {
|
||||||
|
return `<div class="viewer-error">${escapeHtml(state.localRepoScanError)}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!results.length) {
|
||||||
|
return `<div class="empty-state local-scan-empty">
|
||||||
|
<div>No local repositories scanned yet</div>
|
||||||
|
<div class="muted">Only local repos with remotes from the selected Gitea server will be shown.</div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `<div class="local-repo-list">
|
||||||
|
${results
|
||||||
|
.map(
|
||||||
|
(repo) => `
|
||||||
|
<article class="local-repo-card">
|
||||||
|
<div class="local-repo-info">
|
||||||
|
<strong>${escapeHtml(repo.name || repoNameFromPath(repo.path))}</strong>
|
||||||
|
<span class="muted" title="${escapeHtml(repo.path)}">${escapeHtml(repo.path)}</span>
|
||||||
|
${repo.matchedRemoteUrl ? `<span class="muted" title="${escapeHtml(repo.matchedRemoteUrl)}">Remote: ${escapeHtml(repo.matchedRemoteUrl)}</span>` : ""}
|
||||||
|
</div>
|
||||||
|
<div class="row wrap">
|
||||||
|
<button class="use-scanned-repo-btn" data-repo-path="${escapeHtml(repo.path)}" data-repo-name="${escapeHtml(repo.name || repoNameFromPath(repo.path))}" type="button">Use</button>
|
||||||
|
<button class="view-scanned-repo-btn primary-blue" data-repo-path="${escapeHtml(repo.path)}" data-repo-name="${escapeHtml(repo.name || repoNameFromPath(repo.path))}" type="button">View files</button>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
function breadcrumbTemplate(repoName, path = "") {
|
function breadcrumbTemplate(repoName, path = "") {
|
||||||
const parts = path.split("/").filter(Boolean);
|
const parts = path.split("/").filter(Boolean);
|
||||||
const crumbs = [`<button class="viewer-crumb-btn" data-viewer-path="" type="button">${escapeHtml(repoName)}</button>`];
|
const crumbs = [`<button class="viewer-crumb-btn" data-viewer-path="" type="button">${escapeHtml(repoName)}</button>`];
|
||||||
@@ -525,7 +587,12 @@ function dashboardView() {
|
|||||||
<ul class="list">
|
<ul class="list">
|
||||||
${state.settings.recentRepositories.length
|
${state.settings.recentRepositories.length
|
||||||
? state.settings.recentRepositories
|
? state.settings.recentRepositories
|
||||||
.map((path) => `<li class="recent-item" title="${escapeHtml(path)}">${escapeHtml(path.split(/[/\\]/).filter(Boolean).pop() || path)}</li>`)
|
.map((path) => `
|
||||||
|
<li>
|
||||||
|
<button class="recent-item" data-recent-repo-path="${escapeHtml(path)}" type="button" title="${escapeHtml(path)}">
|
||||||
|
${escapeHtml(repoNameFromPath(path))}
|
||||||
|
</button>
|
||||||
|
</li>`)
|
||||||
.join("")
|
.join("")
|
||||||
: "<li class='muted'>No recent repositories.</li>"}
|
: "<li class='muted'>No recent repositories.</li>"}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -544,6 +611,23 @@ function dashboardView() {
|
|||||||
|
|
||||||
${activeMainTab === "repos" ? `
|
${activeMainTab === "repos" ? `
|
||||||
<section class="panel stack">
|
<section class="panel stack">
|
||||||
|
<div class="local-scan-panel stack">
|
||||||
|
<div class="section-header">
|
||||||
|
<div>
|
||||||
|
<h4 class="title local-scan-title">Find local repositories</h4>
|
||||||
|
<p class="subtitle">Shows only local repos that belong to the selected Gitea server.</p>
|
||||||
|
</div>
|
||||||
|
<button id="scan-local-repos-btn" class="primary" type="button" ${state.localRepoScanLoading ? "disabled" : ""}>
|
||||||
|
${state.localRepoScanLoading ? "Scanning..." : "Scan for repos"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<input id="local-repo-scan-root-input" placeholder="Folder to scan, e.g. F:\\Repos" value="${escapeHtml(state.localRepoScanRootInput || state.settings.defaultCloneDirectory)}" />
|
||||||
|
<input id="local-repo-path-input" placeholder="Or paste a repo path…" value="${escapeHtml(state.localRepoPathInput)}" />
|
||||||
|
<button id="open-local-repo-btn" type="button">Open</button>
|
||||||
|
</div>
|
||||||
|
${localRepoScanTemplate()}
|
||||||
|
</div>
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<h3 class="title">Repositories</h3>
|
<h3 class="title">Repositories</h3>
|
||||||
<span class="muted">${visibleRepos.length} shown</span>
|
<span class="muted">${visibleRepos.length} shown</span>
|
||||||
@@ -582,15 +666,48 @@ function dashboardView() {
|
|||||||
</div>`}
|
</div>`}
|
||||||
</section>
|
</section>
|
||||||
` : activeMainTab === "local" ? `
|
` : activeMainTab === "local" ? `
|
||||||
<section class="panel stack">
|
<div class="gd-toolbar">
|
||||||
<h3 class="title">Local Repository</h3>
|
|
||||||
<div class="row">
|
|
||||||
<input id="local-repo-path-input" placeholder="Path to local repository…" value="${escapeHtml(state.localRepoPathInput)}" />
|
|
||||||
<button id="open-local-repo-btn" type="button">Open</button>
|
|
||||||
</div>
|
|
||||||
${state.selectedRepoName
|
${state.selectedRepoName
|
||||||
? `<div class="selected-repo"><span class="label">Active: </span>${escapeHtml(state.selectedRepoName)}</div>`
|
? `<button class="gd-toolbar-cell selected-repo-tab" type="button" title="${escapeHtml(state.selectedRepoPath)}">
|
||||||
: ""}
|
<span class="gd-cell-icon">${LOCAL_REPO_ICON}</span>
|
||||||
|
<span class="gd-cell-copy">
|
||||||
|
<span class="gd-cell-label">Current repository</span>
|
||||||
|
<span class="gd-cell-value">${escapeHtml(state.selectedRepoName)}</span>
|
||||||
|
</span>
|
||||||
|
<svg class="gd-cell-caret" viewBox="0 0 16 16" width="10" height="10" aria-hidden="true"><path fill="currentColor" d="M4.427 7.427l3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"/></svg>
|
||||||
|
</button>`
|
||||||
|
: `<div class="gd-toolbar-cell gd-toolbar-cell-empty">
|
||||||
|
<span class="gd-cell-icon">${LOCAL_REPO_ICON}</span>
|
||||||
|
<span class="gd-cell-copy">
|
||||||
|
<span class="gd-cell-label">Current repository</span>
|
||||||
|
<span class="gd-cell-value gd-cell-value-muted">No repository selected</span>
|
||||||
|
</span>
|
||||||
|
</div>`}
|
||||||
|
<button class="gd-toolbar-cell" type="button" disabled title="Branch switching coming soon">
|
||||||
|
<span class="gd-cell-icon">${BRANCH_ICON}</span>
|
||||||
|
<span class="gd-cell-copy">
|
||||||
|
<span class="gd-cell-label">Current branch</span>
|
||||||
|
<span class="gd-cell-value">${escapeHtml(state.selectedRepoName ? "main" : "—")}</span>
|
||||||
|
</span>
|
||||||
|
<svg class="gd-cell-caret" viewBox="0 0 16 16" width="10" height="10" aria-hidden="true"><path fill="currentColor" d="M4.427 7.427l3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"/></svg>
|
||||||
|
</button>
|
||||||
|
<button class="gd-toolbar-cell" id="git-pull-btn-toolbar" type="button" ${state.selectedRepoName ? "" : "disabled"}>
|
||||||
|
<span class="gd-cell-icon">${SYNC_ICON}</span>
|
||||||
|
<span class="gd-cell-copy">
|
||||||
|
<span class="gd-cell-label">Fetch origin</span>
|
||||||
|
<span class="gd-cell-value">Sync changes</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<section class="panel stack">
|
||||||
|
<h3 class="title">${escapeHtml(state.selectedRepoName || "Local Repository")}</h3>
|
||||||
|
${state.selectedRepoName
|
||||||
|
? `<div class="muted selected-repo-path-line" title="${escapeHtml(state.selectedRepoPath)}">${escapeHtml(state.selectedRepoPath)}</div>`
|
||||||
|
: `<div class="empty-state">
|
||||||
|
<div>No repository selected</div>
|
||||||
|
<div class="muted">Pick a repository from <strong>Recent repositories</strong> on the left, or scan for local repos on the <strong>Repositories</strong> tab.</div>
|
||||||
|
</div>`}
|
||||||
|
${state.selectedRepoName ? `
|
||||||
<div class="row wrap">
|
<div class="row wrap">
|
||||||
<button id="git-status-btn" type="button">Status</button>
|
<button id="git-status-btn" type="button">Status</button>
|
||||||
<button id="git-branch-btn" type="button">Branch</button>
|
<button id="git-branch-btn" type="button">Branch</button>
|
||||||
@@ -606,6 +723,7 @@ function dashboardView() {
|
|||||||
${gitOutput
|
${gitOutput
|
||||||
? `<pre class="git-output">${escapeHtml(gitOutput)}</pre>`
|
? `<pre class="git-output">${escapeHtml(gitOutput)}</pre>`
|
||||||
: `<p class="muted git-output-placeholder">Run a git command to see output here.</p>`}
|
: `<p class="muted git-output-placeholder">Run a git command to see output here.</p>`}
|
||||||
|
` : ""}
|
||||||
</section>
|
</section>
|
||||||
` : viewerTemplate()}
|
` : viewerTemplate()}
|
||||||
</main>
|
</main>
|
||||||
@@ -810,6 +928,59 @@ async function autoLoadReadme() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectLocalRepo(path, name = "") {
|
||||||
|
const state = getState();
|
||||||
|
state.localRepoPathInput = path;
|
||||||
|
state.selectedRepoPath = path;
|
||||||
|
state.selectedRepoName = name || repoNameFromPath(path);
|
||||||
|
addRecentRepo(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function scanForLocalRepos() {
|
||||||
|
const state = getState();
|
||||||
|
const rootInput = document.getElementById("local-repo-scan-root-input")?.value?.trim() || "";
|
||||||
|
state.localRepoScanRootInput = rootInput;
|
||||||
|
|
||||||
|
if (!getActiveServer()) {
|
||||||
|
state.localRepoScanResults = [];
|
||||||
|
state.localRepoScanError = "Select a Gitea server before scanning local repositories.";
|
||||||
|
render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allowedRemoteUrls = serverRepoRemoteUrls();
|
||||||
|
if (!allowedRemoteUrls.length) {
|
||||||
|
state.localRepoScanResults = [];
|
||||||
|
state.localRepoScanError = "No repository clone URLs are loaded for the selected Gitea server. Refresh repositories and try again.";
|
||||||
|
render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.localRepoScanLoading = true;
|
||||||
|
state.localRepoScanError = "";
|
||||||
|
render();
|
||||||
|
|
||||||
|
const roots = [rootInput, state.settings.defaultCloneDirectory].filter(Boolean);
|
||||||
|
try {
|
||||||
|
state.localRepoScanResults = await scanLocalRepos(
|
||||||
|
[...new Set(roots)],
|
||||||
|
allowedRemoteUrls,
|
||||||
|
state.settings.gitExecutablePath,
|
||||||
|
4,
|
||||||
|
200
|
||||||
|
);
|
||||||
|
if (!state.localRepoScanResults.length) {
|
||||||
|
state.localRepoScanError = "No local repositories from the selected Gitea server were found in the scanned folders.";
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
state.localRepoScanResults = [];
|
||||||
|
state.localRepoScanError = `Repo scan failed: ${error.message}`;
|
||||||
|
} finally {
|
||||||
|
state.localRepoScanLoading = false;
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadViewerPath(path = "") {
|
async function loadViewerPath(path = "") {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const viewer = state.viewer;
|
const viewer = state.viewer;
|
||||||
@@ -1008,6 +1179,14 @@ function bindDashboardEvents() {
|
|||||||
render();
|
render();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll(".recent-item").forEach((button) => {
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
selectLocalRepo(button.dataset.recentRepoPath || "");
|
||||||
|
activeMainTab = "local";
|
||||||
|
render();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelectorAll("[data-right-tab]").forEach((btn) => {
|
document.querySelectorAll("[data-right-tab]").forEach((btn) => {
|
||||||
btn.addEventListener("click", () => {
|
btn.addEventListener("click", () => {
|
||||||
activeRightTab = btn.dataset.rightTab;
|
activeRightTab = btn.dataset.rightTab;
|
||||||
@@ -1054,22 +1233,33 @@ function bindDashboardEvents() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("scan-local-repos-btn")?.addEventListener("click", () => {
|
||||||
|
scanForLocalRepos();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll(".use-scanned-repo-btn").forEach((button) => {
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
selectLocalRepo(button.dataset.repoPath || "", button.dataset.repoName || "");
|
||||||
|
render();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll(".view-scanned-repo-btn").forEach((button) => {
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
selectLocalRepo(button.dataset.repoPath || "", button.dataset.repoName || "");
|
||||||
|
openLocalViewer();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("open-local-repo-btn")?.addEventListener("click", () => {
|
document.getElementById("open-local-repo-btn")?.addEventListener("click", () => {
|
||||||
// MVP local detection is user-driven path entry; folder picker can be added next.
|
|
||||||
const value = document.getElementById("local-repo-path-input")?.value?.trim() || "";
|
const value = document.getElementById("local-repo-path-input")?.value?.trim() || "";
|
||||||
state.localRepoPathInput = value;
|
selectLocalRepo(value);
|
||||||
state.selectedRepoPath = value;
|
|
||||||
state.selectedRepoName = value.split(/[/\\]/).filter(Boolean).pop() || value;
|
|
||||||
addRecentRepo(value);
|
|
||||||
render();
|
render();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("view-local-repo-btn")?.addEventListener("click", () => {
|
document.getElementById("view-local-repo-btn")?.addEventListener("click", () => {
|
||||||
const value = document.getElementById("local-repo-path-input")?.value?.trim() || state.selectedRepoPath;
|
const value = document.getElementById("local-repo-path-input")?.value?.trim() || state.selectedRepoPath;
|
||||||
state.localRepoPathInput = value;
|
if (value) selectLocalRepo(value);
|
||||||
state.selectedRepoPath = value;
|
|
||||||
state.selectedRepoName = value.split(/[/\\]/).filter(Boolean).pop() || value;
|
|
||||||
if (value) addRecentRepo(value);
|
|
||||||
openLocalViewer();
|
openLocalViewer();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1106,6 +1296,9 @@ function bindDashboardEvents() {
|
|||||||
document.getElementById("git-pull-btn")?.addEventListener("click", () => {
|
document.getElementById("git-pull-btn")?.addEventListener("click", () => {
|
||||||
runRepoCommand("Pull", () => runGitPull(state.selectedRepoPath, state.settings.gitExecutablePath));
|
runRepoCommand("Pull", () => runGitPull(state.selectedRepoPath, state.settings.gitExecutablePath));
|
||||||
});
|
});
|
||||||
|
document.getElementById("git-pull-btn-toolbar")?.addEventListener("click", () => {
|
||||||
|
runRepoCommand("Pull", () => runGitPull(state.selectedRepoPath, state.settings.gitExecutablePath));
|
||||||
|
});
|
||||||
document.getElementById("git-push-btn")?.addEventListener("click", () => {
|
document.getElementById("git-push-btn")?.addEventListener("click", () => {
|
||||||
runRepoCommand("Push", () => runGitPush(state.selectedRepoPath, state.settings.gitExecutablePath));
|
runRepoCommand("Push", () => runGitPush(state.selectedRepoPath, state.settings.gitExecutablePath));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ const state = {
|
|||||||
selectedRepoName: "",
|
selectedRepoName: "",
|
||||||
repoSearch: "",
|
repoSearch: "",
|
||||||
localRepoPathInput: "",
|
localRepoPathInput: "",
|
||||||
|
localRepoScanRootInput: "",
|
||||||
|
localRepoScanResults: [],
|
||||||
|
localRepoScanLoading: false,
|
||||||
|
localRepoScanError: "",
|
||||||
cloneUrlInput: "",
|
cloneUrlInput: "",
|
||||||
cloneDestinationInput: "",
|
cloneDestinationInput: "",
|
||||||
commitMessage: "",
|
commitMessage: "",
|
||||||
|
|||||||
@@ -35,6 +35,17 @@ export async function runGitBranch(repoPath, gitPath) {
|
|||||||
return invoke("git_branch", { repoPath, gitPath: gitPath || null });
|
return invoke("git_branch", { repoPath, gitPath: gitPath || null });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function scanLocalRepos(roots = [], allowedRemoteUrls = [], gitPath = "", maxDepth = 4, maxResults = 200) {
|
||||||
|
ensureInvoke();
|
||||||
|
return invoke("scan_local_repos", {
|
||||||
|
roots,
|
||||||
|
allowedRemoteUrls,
|
||||||
|
gitPath: gitPath || null,
|
||||||
|
maxDepth,
|
||||||
|
maxResults,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function listLocalRepoBranches(repoPath, gitPath) {
|
export async function listLocalRepoBranches(repoPath, gitPath) {
|
||||||
ensureInvoke();
|
ensureInvoke();
|
||||||
return invoke("local_repo_branches", { repoPath, gitPath: gitPath || null });
|
return invoke("local_repo_branches", { repoPath, gitPath: gitPath || null });
|
||||||
|
|||||||
+294
-2
@@ -1,7 +1,11 @@
|
|||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use reqwest::header::{ACCEPT, AUTHORIZATION};
|
use reqwest::header::{ACCEPT, AUTHORIZATION};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -47,6 +51,14 @@ struct LocalRepoFile {
|
|||||||
too_large: bool,
|
too_large: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct LocalRepoCandidate {
|
||||||
|
name: String,
|
||||||
|
path: String,
|
||||||
|
matched_remote_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
fn normalize_api_base_url(server_url: &str) -> Result<String, String> {
|
fn normalize_api_base_url(server_url: &str) -> Result<String, String> {
|
||||||
// Normalize user input so every backend consistently resolves to /api/v1.
|
// Normalize user input so every backend consistently resolves to /api/v1.
|
||||||
let trimmed = server_url.trim().trim_end_matches('/');
|
let trimmed = server_url.trim().trim_end_matches('/');
|
||||||
@@ -164,6 +176,206 @@ fn treeish(reference: &str, path: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dedupe_key(path: &Path) -> String {
|
||||||
|
let path = path
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap_or_else(|_| path.to_path_buf())
|
||||||
|
.to_string_lossy()
|
||||||
|
.replace('\\', "/")
|
||||||
|
.trim_end_matches('/')
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
path.to_lowercase()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_if_exists(paths: &mut Vec<PathBuf>, path: PathBuf) {
|
||||||
|
if !path.exists() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = dedupe_key(&path);
|
||||||
|
if !paths.iter().any(|existing| dedupe_key(existing) == key) {
|
||||||
|
paths.push(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_repo_scan_roots() -> Vec<PathBuf> {
|
||||||
|
let mut roots = Vec::new();
|
||||||
|
|
||||||
|
if let Some(home) = env::var_os("USERPROFILE").or_else(|| env::var_os("HOME")) {
|
||||||
|
let home = PathBuf::from(home);
|
||||||
|
add_if_exists(&mut roots, home.join("Repos"));
|
||||||
|
add_if_exists(&mut roots, home.join("repos"));
|
||||||
|
add_if_exists(&mut roots, home.join("Code"));
|
||||||
|
add_if_exists(&mut roots, home.join("code"));
|
||||||
|
add_if_exists(&mut roots, home.join("Source"));
|
||||||
|
add_if_exists(&mut roots, home.join("source"));
|
||||||
|
add_if_exists(&mut roots, home.join("Projects"));
|
||||||
|
add_if_exists(&mut roots, home.join("GitHub"));
|
||||||
|
add_if_exists(&mut roots, home.join("Documents").join("GitHub"));
|
||||||
|
add_if_exists(&mut roots, home.join("Documents").join("Repos"));
|
||||||
|
add_if_exists(&mut roots, home.join("Desktop"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
for drive in b'A'..=b'Z' {
|
||||||
|
let root = format!("{}:\\", drive as char);
|
||||||
|
let root_path = PathBuf::from(&root);
|
||||||
|
if !root_path.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for folder in [
|
||||||
|
"Repos", "repos", "Code", "code", "Source", "source", "Projects", "GitHub", "Dev",
|
||||||
|
] {
|
||||||
|
add_if_exists(&mut roots, root_path.join(folder));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
roots
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_skippable_dir(path: &Path) -> bool {
|
||||||
|
let Some(name) = path.file_name().and_then(|value| value.to_str()) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
matches!(
|
||||||
|
name,
|
||||||
|
".cache"
|
||||||
|
| ".cargo"
|
||||||
|
| ".gradle"
|
||||||
|
| ".npm"
|
||||||
|
| ".rustup"
|
||||||
|
| ".svn"
|
||||||
|
| ".tauri"
|
||||||
|
| "AppData"
|
||||||
|
| "Library"
|
||||||
|
| "node_modules"
|
||||||
|
| "target"
|
||||||
|
| "vendor"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_git_repo(path: &Path) -> bool {
|
||||||
|
path.join(".git").exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn normalize_git_remote_url(value: &str) -> String {
|
||||||
|
let mut remote = value.trim().trim_end_matches('/').to_lowercase();
|
||||||
|
if let Some(stripped) = remote.strip_suffix(".git") {
|
||||||
|
remote = stripped.to_string();
|
||||||
|
}
|
||||||
|
remote
|
||||||
|
}
|
||||||
|
|
||||||
|
fn local_remote_urls(repo_path: &Path, git_path: Option<String>) -> Vec<String> {
|
||||||
|
let git_binary = resolve_git_binary(git_path);
|
||||||
|
let Ok(output) = Command::new(&git_binary)
|
||||||
|
.current_dir(repo_path)
|
||||||
|
.args(["config", "--get-regexp", r"^remote\..*\.url$"])
|
||||||
|
.output()
|
||||||
|
else {
|
||||||
|
return Vec::new();
|
||||||
|
};
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
String::from_utf8_lossy(&output.stdout)
|
||||||
|
.lines()
|
||||||
|
.filter_map(|line| line.split_once(' ').map(|(_, url)| url.trim().to_string()))
|
||||||
|
.filter(|url| !url.is_empty())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn matched_server_remote(
|
||||||
|
repo_path: &Path,
|
||||||
|
git_path: Option<String>,
|
||||||
|
allowed_remote_urls: &HashSet<String>,
|
||||||
|
) -> Option<String> {
|
||||||
|
local_remote_urls(repo_path, git_path)
|
||||||
|
.into_iter()
|
||||||
|
.find(|remote| allowed_remote_urls.contains(&normalize_git_remote_url(remote)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect_repo_candidates(
|
||||||
|
root: &Path,
|
||||||
|
depth: u8,
|
||||||
|
max_depth: u8,
|
||||||
|
results: &mut Vec<LocalRepoCandidate>,
|
||||||
|
seen: &mut HashSet<String>,
|
||||||
|
allowed_remote_urls: &HashSet<String>,
|
||||||
|
git_path: Option<String>,
|
||||||
|
max_results: usize,
|
||||||
|
) {
|
||||||
|
if results.len() >= max_results || is_skippable_dir(root) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_git_repo(root) {
|
||||||
|
if seen.insert(dedupe_key(root)) {
|
||||||
|
let display_path = root.canonicalize().unwrap_or_else(|_| root.to_path_buf());
|
||||||
|
let path = display_path.to_string_lossy().to_string();
|
||||||
|
let Some(matched_remote_url) =
|
||||||
|
matched_server_remote(root, git_path.clone(), allowed_remote_urls)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let name = root
|
||||||
|
.file_name()
|
||||||
|
.and_then(|value| value.to_str())
|
||||||
|
.unwrap_or(&path)
|
||||||
|
.to_string();
|
||||||
|
results.push(LocalRepoCandidate {
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
matched_remote_url,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if depth >= max_depth {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Ok(entries) = fs::read_dir(root) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
if results.len() >= max_results {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_dir() {
|
||||||
|
collect_repo_candidates(
|
||||||
|
&path,
|
||||||
|
depth + 1,
|
||||||
|
max_depth,
|
||||||
|
results,
|
||||||
|
seen,
|
||||||
|
allowed_remote_urls,
|
||||||
|
git_path.clone(),
|
||||||
|
max_results,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn git_clone(
|
fn git_clone(
|
||||||
repo_url: String,
|
repo_url: String,
|
||||||
@@ -203,7 +415,11 @@ fn git_status(repo_path: String, git_path: Option<String>) -> Result<GitCommandR
|
|||||||
run_git_command(
|
run_git_command(
|
||||||
Some(repo_path.trim()),
|
Some(repo_path.trim()),
|
||||||
git_path,
|
git_path,
|
||||||
vec!["status".to_string(), "--short".to_string(), "--branch".to_string()],
|
vec![
|
||||||
|
"status".to_string(),
|
||||||
|
"--short".to_string(),
|
||||||
|
"--branch".to_string(),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +432,77 @@ fn git_branch(repo_path: String, git_path: Option<String>) -> Result<GitCommandR
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn scan_local_repos(
|
||||||
|
roots: Option<Vec<String>>,
|
||||||
|
allowed_remote_urls: Vec<String>,
|
||||||
|
git_path: Option<String>,
|
||||||
|
max_depth: Option<u8>,
|
||||||
|
max_results: Option<usize>,
|
||||||
|
) -> Result<Vec<LocalRepoCandidate>, String> {
|
||||||
|
let max_depth = max_depth.unwrap_or(4).clamp(1, 8);
|
||||||
|
let max_results = max_results.unwrap_or(200).clamp(1, 500);
|
||||||
|
let allowed_remote_urls = allowed_remote_urls
|
||||||
|
.into_iter()
|
||||||
|
.map(|url| normalize_git_remote_url(&url))
|
||||||
|
.filter(|url| !url.is_empty())
|
||||||
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
|
if allowed_remote_urls.is_empty() {
|
||||||
|
return Err(
|
||||||
|
"No selected server repository URLs are available to match against.".to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let root_paths = roots
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.map(|path| path.trim().to_string())
|
||||||
|
.filter(|path| !path.is_empty())
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let root_paths = if root_paths.is_empty() {
|
||||||
|
default_repo_scan_roots()
|
||||||
|
} else {
|
||||||
|
root_paths
|
||||||
|
};
|
||||||
|
|
||||||
|
if root_paths.is_empty() {
|
||||||
|
return Err(
|
||||||
|
"No scan roots found. Set a default clone directory or enter a scan root.".to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut results = Vec::new();
|
||||||
|
let mut seen = HashSet::new();
|
||||||
|
for root in root_paths {
|
||||||
|
if root.exists() && root.is_dir() {
|
||||||
|
collect_repo_candidates(
|
||||||
|
&root,
|
||||||
|
0,
|
||||||
|
max_depth,
|
||||||
|
&mut results,
|
||||||
|
&mut seen,
|
||||||
|
&allowed_remote_urls,
|
||||||
|
git_path.clone(),
|
||||||
|
max_results,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if results.len() >= max_results {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
results.sort_by(|a, b| {
|
||||||
|
a.name
|
||||||
|
.to_lowercase()
|
||||||
|
.cmp(&b.name.to_lowercase())
|
||||||
|
.then_with(|| a.path.to_lowercase().cmp(&b.path.to_lowercase()))
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(results)
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn local_repo_branches(
|
fn local_repo_branches(
|
||||||
repo_path: String,
|
repo_path: String,
|
||||||
@@ -275,7 +562,11 @@ fn local_repo_tree(
|
|||||||
let output = run_git_output(
|
let output = run_git_output(
|
||||||
repo_path.trim(),
|
repo_path.trim(),
|
||||||
git_path,
|
git_path,
|
||||||
vec!["ls-tree".to_string(), "-l".to_string(), treeish(&reference, &path)],
|
vec![
|
||||||
|
"ls-tree".to_string(),
|
||||||
|
"-l".to_string(),
|
||||||
|
treeish(&reference, &path),
|
||||||
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut entries = Vec::new();
|
let mut entries = Vec::new();
|
||||||
@@ -447,6 +738,7 @@ pub fn run() {
|
|||||||
git_push,
|
git_push,
|
||||||
git_status,
|
git_status,
|
||||||
git_branch,
|
git_branch,
|
||||||
|
scan_local_repos,
|
||||||
local_repo_branches,
|
local_repo_branches,
|
||||||
local_repo_tree,
|
local_repo_tree,
|
||||||
local_repo_file,
|
local_repo_file,
|
||||||
|
|||||||
Reference in New Issue
Block a user