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, .. }
24            | Self::Linear { owner, repo, .. }
25            | Self::Jira { owner, repo, .. }
26            | Self::Adhoc { owner, repo, .. } => dirs::home_dir()
27                .expect("could not determine home directory")
28                .join("worktrees")
29                .join("github")
30                .join(owner)
31                .join(repo),
32            Self::GitLab { owner, repo, .. } => dirs::home_dir()
33                .expect("could not determine home directory")
34                .join("worktrees")
35                .join("gitlab")
36                .join(owner)
37                .join(repo),
38            Self::AzureDevOps {
39                org, project, repo, ..
40            } => dirs::home_dir()
41                .expect("could not determine home directory")
42                .join("worktrees")
43                .join("azuredevops")
44                .join(org)
45                .join(project)
46                .join(repo),
47            Self::RemoteBranch {
48                host, owner, repo, ..
49            } => dirs::home_dir()
50                .expect("could not determine home directory")
51                .join("worktrees")
52                .join(host)
53                .join(owner)
54                .join(repo),
55            Self::Local { project_path, .. } => {
56                let project_name = project_path
57                    .file_name()
58                    .unwrap_or_default()
59                    .to_string_lossy();
60                dirs::home_dir()
61                    .expect("could not determine home directory")
62                    .join("worktrees")
63                    .join("local")
64                    .join(project_name.as_ref())
65            }
66        }
67    }
68}