Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions staged/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub struct BranchWithWorkdir {
pub workspace_status: Option<store::WorkspaceStatus>,
pub agent: Option<String>,
pub worktree_path: Option<String>,
pub is_main_worktree: bool,
pub created_at: i64,
pub updated_at: i64,
}
Expand Down Expand Up @@ -430,7 +429,20 @@ fn import_existing_worktrees(

let mut imported_count = 0;

let canonical_repo = repo_path
.canonicalize()
.unwrap_or_else(|_| repo_path.to_path_buf());

for (worktree_path, branch_name) in worktrees {
// Skip the main worktree (the repo checkout itself)
let canonical_wt = worktree_path
.canonicalize()
.unwrap_or_else(|_| worktree_path.clone());
if canonical_wt == canonical_repo {
log::debug!("Skipping main worktree at {}", worktree_path.display());
continue;
}

let branch_name = match branch_name {
Some(name) => name,
None => {
Expand Down Expand Up @@ -570,7 +582,6 @@ fn to_branch_with_workdir(
workspace_status: branch.workspace_status,
agent: branch.agent,
worktree_path: workdir_path,
is_main_worktree: false,
created_at: branch.created_at,
updated_at: branch.updated_at,
}
Expand All @@ -582,15 +593,11 @@ fn list_branches_for_project(
project_id: String,
) -> Result<Vec<BranchWithWorkdir>, String> {
let store = get_store(&store)?;
let project = store
let _project = store
.get_project(&project_id)
.map_err(|e| e.to_string())?
.ok_or_else(|| format!("Project not found: {project_id}"))?;

let canonical_repo = Path::new(&project.repo_path)
.canonicalize()
.unwrap_or_else(|_| PathBuf::from(&project.repo_path));

let branches = store
.list_branches_for_project(&project_id)
.map_err(|e| e.to_string())?;
Expand All @@ -601,15 +608,7 @@ fn list_branches_for_project(
.get_workdir_for_branch(&branch.id)
.map_err(|e| e.to_string())?;

let is_main = workdir.as_ref().is_some_and(|w| {
Path::new(&w.path)
.canonicalize()
.unwrap_or_else(|_| PathBuf::from(&w.path))
== canonical_repo
});

let mut bw = to_branch_with_workdir(branch, workdir.map(|w| w.path));
bw.is_main_worktree = is_main;
let bw = to_branch_with_workdir(branch, workdir.map(|w| w.path));
result.push(bw);
}
Ok(result)
Expand Down Expand Up @@ -852,19 +851,6 @@ async fn delete_branch(
.get_workdir_for_branch(&branch_id)
.map_err(|e| e.to_string())?;

// Prevent deletion of the main worktree (the repo checkout itself)
if let Some(ref wd) = workdir {
let canonical_repo = Path::new(&project.repo_path)
.canonicalize()
.unwrap_or_else(|_| PathBuf::from(&project.repo_path));
let canonical_wd = Path::new(&wd.path)
.canonicalize()
.unwrap_or_else(|_| PathBuf::from(&wd.path));
if canonical_wd == canonical_repo {
return Err("Cannot delete the main worktree".to_string());
}
}

if let Some(ref wd) = workdir {
let repo_path = Path::new(&project.repo_path);
let worktree_path = Path::new(&wd.path);
Expand Down
24 changes: 5 additions & 19 deletions staged/src/lib/BranchCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,6 @@
<div class="branch-info">
<GitBranch size={16} class="branch-icon" />
<span class="branch-name">{branch.branchName}</span>
{#if branch.isMainWorktree}
<span class="main-badge">main worktree</span>
{/if}
<span class="branch-separator">›</span>
<span class="base-branch-name">{formatBaseBranch(branch.baseBranch)}</span>
</div>
Expand Down Expand Up @@ -718,13 +715,11 @@
{/if}

<!-- Delete last -->
{#if !branch.isMainWorktree}
<div class="menu-separator"></div>
<button class="more-menu-item danger" onclick={handleDeleteFromMenu}>
<Trash2 size={14} />
Delete
</button>
{/if}
<div class="menu-separator"></div>
<button class="more-menu-item danger" onclick={handleDeleteFromMenu}>
<Trash2 size={14} />
Delete
</button>
</div>
{/if}
</div>
Expand Down Expand Up @@ -1040,15 +1035,6 @@
letter-spacing: -0.01em;
}

.main-badge {
font-size: var(--size-xs);
font-weight: 500;
color: var(--text-faint);
background-color: var(--bg-hover);
padding: 1px 6px;
border-radius: 4px;
}

.branch-separator {
color: var(--text-faint);
font-size: var(--size-md);
Expand Down
1 change: 0 additions & 1 deletion staged/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface Branch {
workspaceStatus: WorkspaceStatus | null;
agent: string | null;
worktreePath: string | null;
isMainWorktree: boolean;
createdAt: number;
updatedAt: number;
}
Expand Down