Skip to main content

worktree_io/issue/
paths.rs

1use std::path::PathBuf;
2
3use super::IssueRef;
4
5impl IssueRef {
6    /// Path to the worktree checkout.
7    ///
8    /// For `Local`: `~/worktrees/local/{project_name}/issue-{display_number}`
9    /// For others:  `~/worktrees/github/{owner}/{repo}/issue-N`
10    pub fn temp_path(&self) -> PathBuf {
11        self.bare_clone_path().join(self.workspace_dir_name())
12    }
13
14    /// Path to the bare clone (or the local repo itself for `Local`).
15    pub fn bare_clone_path(&self) -> PathBuf {
16        match self {
17            Self::GitHub { owner, repo, .. } | Self::Linear { owner, repo, .. } => dirs::home_dir()
18                .expect("could not determine home directory")
19                .join("worktrees")
20                .join("github")
21                .join(owner)
22                .join(repo),
23            Self::Local { project_path, .. } => {
24                let project_name = project_path
25                    .file_name()
26                    .unwrap_or_default()
27                    .to_string_lossy();
28                dirs::home_dir()
29                    .expect("could not determine home directory")
30                    .join("worktrees")
31                    .join("local")
32                    .join(project_name.as_ref())
33            }
34        }
35    }
36}