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

Pulsar doesn't update file buffers correctly when switching branches #1227

Open
5 tasks done
backit opened this issue Feb 19, 2025 · 7 comments
Open
5 tasks done

Pulsar doesn't update file buffers correctly when switching branches #1227

backit opened this issue Feb 19, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@backit
Copy link

backit commented Feb 19, 2025

Thanks in advance for your bug report!

  • Have you reproduced issue in safe mode?
  • Have you used the debugging guide to try to resolve the issue?
  • Have you checked our FAQs to make sure your question isn't answered there?
  • Have you checked to make sure your issue does not already exist?
  • Have you checked you are on the latest release of Pulsar?

What happened?

Hi,
i think this is the same issue on atom
atom/atom#4982
If you change branch via cli, pulsar does not reflect this leaving files opened, very dangerous.
Steps to reproduce:
in a git repo, from "dev" branch make a "test" branch, now open pulsar and create a file testfile and commit
Leave Pulsar opened and from cli change branch to "dev".
testfile should be closed on Pulsar and not visible from tree.
Instead it stay open and if you modify and save it you'll find in "dev" branch".

This is particularly dangerous when you have same files with different content, for example via cli in testfile in test branch write "lorem ipsum" and save 'n' commit, now change to dev branch and in testfile write "ipsum lorem" save n commit, open pulsar you are in dev branch, modify the file and s'n'c, change to test branch the file show the content from dev branch!! if you save you'll overwrite the file in branch "test" !!! O.O

Pulsar version

1.125.2025012404

Which OS does this happen on?

🐧 Debian based (Linux Mint, Ubuntu, etc.)

OS details

Ubuntu 22.04

Which CPU architecture are you running this on?

x86_64/AMD64

What steps are needed to reproduce this?

  1. in a git repo, from "dev" branch make a "test" branch
  2. open pulsar and create a file testfile and commit
  3. Leave Pulsar opened and from cli change branch to "dev".

testfile should be closed on Pulsar and not visible from tree.
Instead it stay open and if you modify and save it you'll find in "dev" branch".

Additional Information:

No response

@backit backit added the bug Something isn't working label Feb 19, 2025
@savetheclocktower
Copy link
Contributor

There's a setting that governs this and it defaults to false. Have you made sure that core.closeDeletedFileTabs is true?

@savetheclocktower
Copy link
Contributor

This is particularly dangerous when you have same files with different content, for example via cli in testfile in test branch write "lorem ipsum" and save 'n' commit, now change to dev branch and in testfile write "ipsum lorem" save n commit, open pulsar you are in dev branch, modify the file and s'n'c, change to test branch the file show the content from dev branch!! if you save you'll overwrite the file in branch "test" !!! O.O

Regardless of the answer to the deleted-file-tabs question, I agree that this aspect is not ideal — I just find it more of an annoyance than a true risk. In this example, the danger of keeping the tab open (possibly overwriting the file if you save by accident) is balanced against the danger of closing the tab proactively (possibly losing your work if you didn't mean for the buffer to close) — but neither one is particularly dangerous, since “Undo” exists and we're talking about a file that's already in version control.

Still, it's worth fixing. VS Code addresses this by introducing a third file state alongside “pristine” and “modified” — one that makes it clear that the file has been deleted from under it:

Image

I've had this in the back of my head for a while and there might even be a ticket for it somewhere.

@backit
Copy link
Author

backit commented Feb 20, 2025

There's a setting that governs this and it defaults to false. Have you made sure that core.closeDeletedFileTabs is true?

No, it was false. I didn't know that option sry.

Still, it's worth fixing. VS Code addresses this by introducing a third file state alongside “pristine” and “modified”
this seems very cool!!

@savetheclocktower
Copy link
Contributor

savetheclocktower commented Feb 20, 2025

Not a problem — I forgot that option even existed until reading through the long, long saga of the ticket you linked.

@savetheclocktower
Copy link
Contributor

savetheclocktower commented Feb 20, 2025

Anyway, here's how it's supposed to work — if it's not working this way for you, please let us know:

  • Suppose you have foo.txt checked into Git and its contents vary between branch-a and branch-b.
  • If foo.txt is open in Pulsar but is pristine (has no unsaved changes), switching from branch-a to branch-b should automatically update the contents of the editor.
  • If foo.txt is open in Pulsar and is modified, switching from branch-a to branch-b will keep the entire content of the buffer in its modified state; if you then save the file, you will indeed overwrite branch-b's copy of foo.txt. This will instantly be visible in the Git pane and you'll be able to discard the changes.
  • If foo.txt is instead present on branch-a but not present on branch-b, when you switch from branch-a to branch-b, foo.txt will show as a modified buffer by default. This is true whether or not you have made unsaved changes to foo.txt. If you've enabled core.closeDeletedFileTabs, these tabs will be automatically closed — presumably only if they were pristine when you switched branches, but I haven't checked yet.

In my experience, everything works as expected when there are no modified buffers. But the features that would be nice to have are these:

  • A “deleted” file state that notifies you when an open and modified buffer has had its underlying file deleted; if you try to save, you'll be prompted for confirmation of your intent.
  • An “updated outside of Pulsar” file state that indicates when a file has changed while you've got unsaved modifications; when you save, you'll be prompted for confirmation. (VS Code also lets you do a diff at this point, but that's a longer-term goal.)

These could work identically whether files are under version control or not.

@savetheclocktower
Copy link
Contributor

Aha — #1040 is the ticket I made for this last year.

@backit
Copy link
Author

backit commented Feb 21, 2025

Anyway, here's how it's supposed to work — if it's not working this way for you, please let us know:

* Suppose you have `foo.txt` checked into Git and its contents vary between `branch-a` and `branch-b`.

* If `foo.txt` is open in Pulsar but is pristine (has no unsaved changes), switching from `branch-a` to `branch-b` should automatically update the contents of the editor.

ok

* If `foo.txt` is open in Pulsar and is modified, switching from `branch-a` to `branch-b` will keep the entire content of the buffer in its modified state; if you then save the file, you will indeed overwrite `branch-b`'s copy of `foo.txt`. This will instantly be visible in the Git pane and you'll be able to discard the changes.

this could be dangerous if i have not opened git tab

* If `foo.txt` is instead present on `branch-a` but not present on `branch-b`, when you switch from `branch-a` to `branch-b`, `foo.txt` will show as a modified buffer by default. This is true whether or not you have made unsaved changes to `foo.txt`. If you've enabled `core.closeDeletedFileTabs`, these tabs will be automatically closed — presumably only if they were pristine when you switched branches, but I haven't checked yet.
* An “updated outside of Pulsar” file state that indicates when a file has changed while you've got unsaved modifications; when you save, you'll be prompted for confirmation. (VS Code also lets you do a diff at this point, but that's a longer-term goal.)

This should be in my opinion, the normal workflow. Kate editor (default kde editor) works like this too. If the file open in your tab changes for whatever reason, kate shows a warning without changing the file you watch and proposing to A: reload the file or B: save your changes overwriting existing file.
This happens regardless the file is saved or not, file is changed under the hood stop.

Btw thanks for your work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants