From 35708105168bacadc8b94179b0b3356ed9548adb Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 May 2023 09:09:09 -0700 Subject: [PATCH] Add API for accessing git branch --- crates/gpui/src/elements/flex.rs | 4 ++++ crates/project/src/worktree.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/gpui/src/elements/flex.rs b/crates/gpui/src/elements/flex.rs index e0e8dfc215069b892fbfc1cd25d640fbdb7f18e2..857f3f56fc08b0b24f39011d7f4323838b97dde2 100644 --- a/crates/gpui/src/elements/flex.rs +++ b/crates/gpui/src/elements/flex.rs @@ -66,6 +66,10 @@ impl Flex { self } + pub fn is_empty(&self) -> bool { + self.children.is_empty() + } + fn layout_flex_children( &mut self, layout_expanded: bool, diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index d663fc8b1145038cf05a6a50f4e3f2ef63cfc98f..fccb382ca52ca9f87729c428798e6c843b034ef2 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -133,6 +133,10 @@ impl RepositoryEntry { pub(crate) fn in_dot_git(&self, path: &Path) -> bool { path.starts_with(self.git_dir_path.as_ref()) } + + pub fn branch(&self) -> Option> { + self.branch.clone() + } } /// This path corresponds to the 'content path' (the folder that contains the .git) @@ -160,6 +164,12 @@ impl Deref for RepositoryWorkDirectory { } } +impl<'a> From<&'a str> for RepositoryWorkDirectory { + fn from(value: &'a str) -> Self { + RepositoryWorkDirectory(Path::new(value).into()) + } +} + #[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)] pub struct RepoPath(PathBuf); @@ -1443,6 +1453,12 @@ impl Snapshot { &self.root_name } + pub fn root_git_entry(&self) -> Option { + self.repository_entries + .get(&"".into()) + .map(|entry| entry.to_owned()) + } + pub fn scan_id(&self) -> usize { self.scan_id }