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 1cac8ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autoload/clap/plugin/git.vim
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ function! clap#plugin#git#set_summary_var(bufnr, summary) abort
call setbufvar(a:bufnr, 'clap_git', clap_git)
endfunction

function! clap#plugin#git#set_branch_var(bufnr, branch) abort
let clap_git = getbufvar(a:bufnr, 'clap_git', {})
let clap_git.branch = a:branch
call setbufvar(a:bufnr, 'clap_git', clap_git)
endfunction

if has('nvim')
function! clap#plugin#git#clear_blame_info(bufnr) abort
let id = getbufvar(a:bufnr, 'clap_git_blame_extmark_id')
Expand Down
9 changes: 9 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,15 @@ 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
.exec("clap#plugin#git#set_branch_var", (bufnr, 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 1cac8ef

Please sign in to comment.