Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to get git repository status from global variable #1075

Closed
Aryonal opened this issue Jun 30, 2024 · 6 comments
Closed

Be able to get git repository status from global variable #1075

Aryonal opened this issue Jun 30, 2024 · 6 comments

Comments

@Aryonal
Copy link
Contributor

Aryonal commented Jun 30, 2024

Description

Thanks to vim.b.gitsigns_* variables, it's really easy to get git status for a buffer. However, I don't find a similar way to fetch the repository git status. I think it would be helpful if we could get the info from a global variable.

Proposal

Create global variables for repository git status, e.g. vim.g.gitsigns_status, and vim.g.gitsigns_status_dict.

Stored information

On different verbosity levels, I would imagine the following information could be stored, from low to high

  1. A flag whether the repo has changed
  2. The number of changed files in total
  3. Sophisticated information on numbers of files in different statuses, like modified, added, staged, etc.
@lewis6991
Copy link
Owner

Sorry but I'll pass, Gitsigns isn't needed for this.

@lewis6991 lewis6991 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2024
@Aryonal
Copy link
Contributor Author

Aryonal commented Jul 4, 2024

@lewis6991 Thank you for responding!

Can I know why isn't Gitsigns needed for this? My apologise if I missed some obvious reasons, or existing implementations.

The reason I ask is that I tried to implement it on my local and it's working, if it's an acceptable feature, I would like to raise a PR if it's allowed.

@WieeRd
Copy link

WieeRd commented Dec 24, 2024

I was about to request the same feature and discovered this issue.
The main reason I wanted this feature is to use it in a global statusline (laststatus=3 or tabline).
If I were to use buffer-local variables in this situation, they would return nil when the window focus is on files outside the repository, such as help page.
I would really appreciate g: variants of currently provided b: variables that represent the git repository status of current $PWD.

Like @Aryonal asked, are we missing something? Is there a trivial way to fetch this information already?
Also, I'd like to point out that while g:gitsigns_head is documented on the help page, they are not actually supported by gitsigns. Perhaps it has been removed and the docs are outdated?

@lewis6991
Copy link
Owner

Also, I'd like to point out that while g:gitsigns_head is documented on the help page, they are not actually supported by gitsigns. Perhaps it has been removed and the docs are outdated?

g:gitsigns_head is supported. I don't know why you think it isn't.

Gitsigns does it contain any code for parsing git status, and there is no plans to add any.

@WieeRd
Copy link

WieeRd commented Dec 24, 2024

Gitsigns does it contain any code for parsing git status, and there is no plans to add any.

That's unfortunate. Didn't expect it to involve implementing a whole new feature, though.
Wouldn't it be possible to adjust the existing code that updates the b: variables to check if $PWD is under b:gitsigns_status_dict["root"], and if it is, update the g: variables with the information just acquired for the buffer local variables?

g:gitsigns_head is supported. I don't know why you think it isn't.

I forgot that the repositories I was on is a bit unconventional.
I checked again and g:gitsigns_head is indeed available on ordinary repositories.

However, :echo g:gitsigns_head seems to always fail when:

  1. $GIT_DIR and $GIT_WORK_TREE are explicitly set. I use bare repository to manage my dotfiles and set these variables before launching neovim when I want to edit my dotfiles.
  2. When inside a worktree.

In both cases, gitsigns correctly shows the diff signs and b: variables are available. However, g:gitsigns_head is not. Is this supposed to happen? Are separate git dirs and worktrees not supported in gitsigns?

@lewis6991
Copy link
Owner

$GIT_DIR and $GIT_WORK_TREE are explicitly set. I use bare repository to manage my dotfiles and set these variables before launching neovim when I want to edit my dotfiles.

Possibly a bug or missing feature, supporting those variables are in scope. Same for work trees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants