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    #[must_use]
11    pub fn temp_path(&self) -> PathBuf {
12        self.bare_clone_path().join(self.workspace_dir_name())
13    }
14
15    /// Path to the bare clone (or the local repo itself for `Local`).
16    ///
17    /// # Panics
18    ///
19    /// Panics if the home directory cannot be determined.
20    #[must_use]
21    pub fn bare_clone_path(&self) -> PathBuf {
22        match self {
23            Self::GitHub { owner, repo, .. } | Self::Linear { owner, repo, .. } => dirs::home_dir()
24                .expect("could not determine home directory")
25                .join("worktrees")
26                .join("github")
27                .join(owner)
28                .join(repo),
29            Self::AzureDevOps {
30                org, project, repo, ..
31            } => dirs::home_dir()
32                .expect("could not determine home directory")
33                .join("worktrees")
34                .join("azuredevops")
35                .join(org)
36                .join(project)
37                .join(repo),
38            Self::Local { project_path, .. } => {
39                let project_name = project_path
40                    .file_name()
41                    .unwrap_or_default()
42                    .to_string_lossy();
43                dirs::home_dir()
44                    .expect("could not determine home directory")
45                    .join("worktrees")
46                    .join("local")
47                    .join(project_name.as_ref())
48            }
49        }
50    }
51}