Skip to content

Commit

Permalink
Initialize b:eleline_branch when git plugin is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Jun 19, 2024
1 parent ebebc16 commit 3ac035f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/maple_core/src/stdio_server/plugin/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
12 changes: 12 additions & 0 deletions crates/maple_core/src/tools/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ impl GitRepo {
Ok(String::from_utf8(output.stdout)?)
}

pub fn fetch_branch(&self) -> Result<String, GitError> {
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<String, GitError> {
let output = std::process::Command::new("git")
Expand Down

0 comments on commit 3ac035f

Please sign in to comment.