diff --git a/crates/maple_core/src/stdio_server/plugin/git.rs b/crates/maple_core/src/stdio_server/plugin/git.rs index 3a0264c6b..be934c3a5 100644 --- a/crates/maple_core/src/stdio_server/plugin/git.rs +++ b/crates/maple_core/src/stdio_server/plugin/git.rs @@ -250,6 +250,18 @@ impl Git { (bufnr, blame_info), )?; } + + if let Ok(branch) = git.fetch_branch() { + if filepath.canonicalize()?.starts_with(&git.repo) { + if git.is_tracked(filepath).unwrap_or(false) { + self.vim.setbufvar( + bufnr, + "eleline_branch", + format!(" {} ", branch.trim()), + )?; + } + } + } } Ok(()) } diff --git a/crates/maple_core/src/tools/git/mod.rs b/crates/maple_core/src/tools/git/mod.rs index 2dd0b3a03..3981354bd 100644 --- a/crates/maple_core/src/tools/git/mod.rs +++ b/crates/maple_core/src/tools/git/mod.rs @@ -373,6 +373,18 @@ impl GitRepo { Ok(String::from_utf8(output.stdout)?) } + pub fn fetch_branch(&self) -> Result { + let output = std::process::Command::new("git") + .current_dir(&self.repo) + .arg("rev-parse") + .arg("--abbrev-ref") + .arg("HEAD") + .stderr(Stdio::null()) + .output()?; + + Ok(String::from_utf8(output.stdout)?) + } + #[allow(unused)] fn fetch_user_name(&self) -> Result { let output = std::process::Command::new("git")