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

restore buffers after git_reset_branch function #1653

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xnorly
Copy link

@xnorly xnorly commented Jan 4, 2022

After undoing commits with telescope's git_reset_branch function, the buffers do not reload and still show the old state. Therefore I added a restore_buffers function in actions/utils.lua, that does exactly that:

  • reloading all the buffers with vim.cmd("bufdo e")
  • turn syntax on again with vim.cmd("syntax on") (because bufdo may turn off syntax to increase speed)
  • show previously shown buffer with vim.cmd("b" .. currentBuff) (because with multiple buffers opened, bufdo will change the view and not return back to the previously shown buffer)

The restore_buffers function could also be used in other git functions. Which is why I added it to the utils module.

@xnorly xnorly changed the title Xnorly buffer reload restore buffers after git_reset_branch function Jan 4, 2022
@kkharji
Copy link
Member

kkharji commented Feb 13, 2022

Interesting fix. I have auto-read enabled so when the file on disk changes the buffer gets updated but this seems to be better way to avoid some errors, in particular, I'm interested to know what will happen in the following cases:

  • buffers open but not saved yet.
  • buffers open but no longer exists after a git command

Additionally, what other function do u think we should have this in.

Thanks for the detailed explanation

@xnorly
Copy link
Author

xnorly commented Feb 28, 2022

Hi tami5
Thanks for your answer.

I have no clue yet about how to treat the situations you mentioned.

Here are other functions that (I think) could make usage of the restore_buffer function:
git_switch_branch
git_apply_stash
git_checkout
git_merge_branch
git_rebase_branch
git_reset_branch

I tried set autoread in vimrc, but it didn't work as expected:
After git_switch_branch, the buffer still showed old branch state. Only after clicking outside the terminal window and clicking back into it, the buffer showed the new state. Maybe it's a setting of my terminal?

best regards

@JoseEscobarBendezu
Copy link

Any update ?

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

Successfully merging this pull request may close these issues.

3 participants