Atom File Auto Reload with Git


#1

Atom’s file reloading doesn’t work quite right with untracked files and git branch switching. To reproduce:

Atom v 1.0.19
Ubuntu 14.04.2 LTS

Leave all file tabs open throughout these steps

  1. Have an <original_branch> with files that don’t exist in <other_branch> with changes in them
  2. git stash (buffers update appropriately)
  3. git checkout <other_branch>
  4. git checkout <original_branch>
  5. git stash pop (file buffers that exist in <other_branch> update, but buffers that only exist in <original_branch> do not)

Your files that didn’t exist in the <other_branch> will not have had the git stash pop changes applied to their buffer, they will be left in the same state as right after the git stash. When closing the files you get an unsaved changes prompt but the tab doesn’t have the unsaved changes mark (has the close tab x instead of blue unsaved circle).

I’m running into this a lot because I make core changes in my branch that need to be cherry-picked upstream. Every time I switch to cherry-pick I run the risk of accidentally saving over my branch files accidentally and without warning.


#2

The cardinal rule of building an editor is:

If there is any question about the right thing to do don’t lose the user’s data

So my first question is, does this cause you to lose data? You don’t make it entirely clear in your workflow example and I’m not sure I can reproduce the issue based on the instructions you’ve given.

The other questions are based on this statement:

Do you have a smaller set of repro steps that display this issue? Can you give an example repo to display this issue in?

Any extra information can help nail this thing down.

Thanks!


#3

It could possibly lose data, though not necessarily. After the git stash pop at the end your buffer shows the files without the stashed changes that were just popped. So if you save without realizing what happened you would overwrite the changes on disk with the stale buffer with no warning, destroying those changes. Closing and reopening the file loads the proper contents from disk.

I don’t have a smaller set of repro steps as of now but I’ll see about setting up a repo for you. In the meantime maybe this example will make the situation clearer:

Imagine a branch master that consists only of master.txt, and a branch dev that only contains master.txt and dev.txt.

I am on my dev branch and have changes in dev.txt that aren’t ready for commit yet, but I need to do something on master quick.

  1. git stash my changes on dev (dev.txt changes)
  2. git checkout master
  3. Do whatever on master
  4. git checkout dev
  5. git stash pop (pops stashed dev.txt changes, but the buffer in Atom does not update with the stash contents)

If I leave dev.txt open this entire time in Atom the buffer does not show the stashed changes that exist on disk at the end. If I inadvertently save dev.txt at this point then it will overwrite the changes that got stash poped.


#4

I set up a test repo as described above: https://github.com/acb/Atom-Test

I just reproduced the issue by opening dev.txt in the dev branch of the repo in Atom, and then performing the above steps exactly. Let me know if I can provide you with any more infomation!

Edit: made a gif showing the behavior I’m seeing. It’s low quality for the sake of size, let me know if you need a sharper one


#5

I assume that is so you don’t lose changes. Does it happen with files that haven’t been edited yet?

I had the same trouble as you just last night. Almost the exact same scenario. Without thinking I just assumed it was doing the right thing. I got in the habit of closing the tabs before popping the stash.


#6

Nothing happens with files that haven’t been edited yet as there’s nothing to stash. The issue is that when the stash pops the buffer doesn’t update with the stashed changes so your buffer and file on disk diverge with no indication (not even the ‘unsaved changes’ blue circle in the tab!).

I don’t imagine many people are checking out branches and then changing files that don’t exist on that branch for later though. I doubt this is intended behavior since files that exist in both branches get silently updated if they have stashed changes that get applied.

I don’t like having to close my tabs…in my current project I have to cherry-pick upstream several times a day and I’m the type of dev that loves to keep everything open all the time. Especially since closing clears bookmarks which are essential for large files!


#7

We are on the exact same page. You should file this as a bug report at atom/atom. Put a link to it here.


#8

Link to bug on github: https://github.com/atom/atom/issues/9257