Unified · Split
| @@ -184,7 +184,9 @@ pub enum Path { · 183 unmodified lines | |||
| 184 | 184 | ||
| 185 | /// | 185 | /// |
| 186 | mod types; | 186 | mod types; |
| 187 | pub use types::{Commit, DetachedObject, Head, Id, Object, Reference, Repository, Tag, ThreadSafeRepository, Tree}; | 187 | pub use types::{ |
| 188 | Commit, DetachedObject, Head, Id, Object, Reference, Repository, RepositoryState, Tag, ThreadSafeRepository, Tree, | ||
| 189 | }; | ||
| 188 | 190 | ||
| 189 | pub mod commit; | 191 | pub mod commit; |
| 190 | pub mod head; | 192 | pub mod head; |
| @@ -78,6 +78,8 @@ mod location; · 77 unmodified lines | |||
| 78 | 78 | ||
| 79 | mod snapshots; | 79 | mod snapshots; |
| 80 | 80 | ||
| 81 | mod state; | ||
| 82 | |||
| 81 | mod impls; | 83 | mod impls; |
| 82 | 84 | ||
| 83 | mod cache; | 85 | mod cache; |
| @@ -0,0 +1,41 @@ | |||
| 1 | use crate::RepositoryState; | ||
| 2 | |||
| 3 | impl crate::Repository { | ||
| 4 | /// Returns the status of an in-progress operation on a repository or [`RepositoryState::None`] | ||
| 5 | /// if nothing is happening. | ||
| 6 | pub fn in_progress_state(&self) -> RepositoryState { | ||
| 7 | let repo_path = self.path(); | ||
| 8 | |||
| 9 | // This is modeled on the logic from wt_status_get_state in git's wt-status.c | ||
| 10 | |||
| 11 | if repo_path.join("rebase-apply/applying").is_file() { | ||
| 12 | return RepositoryState::ApplyMailbox; | ||
| 13 | } else if repo_path.join("rebase-apply").is_dir() { | ||
| 14 | // Should this be a separate RebaseApplyMailbox or ApplyMailboxMerge? | ||
| 15 | return RepositoryState::Rebase; | ||
| 16 | } else if repo_path.join("rebase-merge/interactive").is_file() { | ||
| 17 | return RepositoryState::RebaseInteractive; | ||
| 18 | } else if repo_path.join("rebase-merge").is_dir() { | ||
| 19 | // Should this be RebaseMerge? | ||
| 20 | return RepositoryState::Rebase; | ||
| 21 | } else if repo_path.join("CHERRY_PICK_HEAD").is_file() { | ||
| 22 | if repo_path.join("todo").is_file() { | ||
| 23 | return RepositoryState::CherryPickSequence; | ||
| 24 | } else { | ||
| 25 | return RepositoryState::CherryPick; | ||
| 26 | } | ||
| 27 | } else if repo_path.join("MERGE_HEAD").is_file() { | ||
| 28 | return RepositoryState::Merge; | ||
| 29 | } else if repo_path.join("BISECT_LOG").is_file() { | ||
| 30 | return RepositoryState::Bisect; | ||
| 31 | } else if repo_path.join("REVERT_HEAD").is_file() { | ||
| 32 | if repo_path.join("todo").is_file() { | ||
| 33 | return RepositoryState::RevertSequence; | ||
| 34 | } else { | ||
| 35 | return RepositoryState::Revert; | ||
| 36 | } | ||
| 37 | } else { | ||
| 38 | return RepositoryState::None; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| @@ -124,6 +124,30 @@ pub struct Repository { · 123 unmodified lines | |||
| 124 | pub(crate) config: crate::config::Cache, | 124 | pub(crate) config: crate::config::Cache, |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | /// The state of a git repository | ||
| 128 | pub enum RepositoryState { | ||
| 129 | /// No operations are in-progress | ||
| 130 | None, | ||
| 131 | /// Merge operation in-progress | ||
| 132 | Merge, | ||
| 133 | /// Revert operation in-progress | ||
| 134 | Revert, | ||
| 135 | /// | ||
| 136 | RevertSequence, | ||
| 137 | /// Cherry pick operation in-progress | ||
| 138 | CherryPick, | ||
| 139 | /// | ||
| 140 | CherryPickSequence, | ||
| 141 | /// Bisect in-progress | ||
| 142 | Bisect, | ||
| 143 | /// Rebase in-progress | ||
| 144 | Rebase, | ||
| 145 | /// Interactive rebase in-progress | ||
| 146 | RebaseInteractive, | ||
| 147 | /// Apply mailbox in-progress | ||
| 148 | ApplyMailbox, | ||
| 149 | } | ||
| 150 | |||
| 127 | /// An instance with access to everything a git repository entails, best imagined as container implementing `Sync + Send` for _most_ | 151 | /// An instance with access to everything a git repository entails, best imagined as container implementing `Sync + Send` for _most_ |
| 128 | /// for system resources required to interact with a `git` repository which are loaded in once the instance is created. | 152 | /// for system resources required to interact with a `git` repository which are loaded in once the instance is created. |
| 129 | /// | 153 | /// |