Why doesn't the newly created tabs/files close when I switch the branch?


If I introduce new files to a branch, I most often leave my tabs open with those new files. After I switch the branch the tabs with new files introduced in first branch still remain there and sometimes I accidentally click on Save when I quit the editor which introduces new files to the branch that I just switched. It’s frustrating because I have to keep track of the files and their branches.
Is there a workaround for this because I think this can cause some serious frustrations on large projects. Also, would be amazing if my workspace gets restored whenever switching the branch.


Atom and Git aren’t integrated that much. Built-in git functions at this time are only used for display purposes, I think. Add-on packages do more.

Does any other editor support this? This would be a nice feature for a package that improves git. Check the existing git packages.


Atom doesn’t know what your intent is when you switch the branch if you have the file open:

  1. You accidentally left it open and think it should be closed
  2. You intend to copy some of the contents from the file into a different file on the master branch
  3. You intend to save the file as is on the master branch
  4. You intend to keep the file open for reference and close it without saving it on the master branch
  5. etc

If there is one thing I’ve learned while participating here is that there are a lot of different workflows (for everything, not just Git) and sometimes it is better if Atom doesn’t make any assumptions. In this case, it makes no assumptions by leaving the file open and letting you close it how you want. Making any other assumption could lead to lost work.


An idea: when a branch is switched and the save dialog pops up, the save dialog could warn you that the branch is changed. This should be a separate package because not everyone has this problem. I don’t because I use a package that saves constantly. I never see the save dialog.


Agreed on not making assumption but there should be atleast some kind of indication from the editor whenever I’m trying to modify the file saying that the file no longer exists so that I don’t have to keep track of the files on branches.

@mark_hahn: So far I’ve only manage to find a package called git-tab-status that color codes the tab based on the state of the file. I guess I can use that for a while but would love for smarter solution to this.


This would be a great time to learn how to code an atom package, if you don’t already know how (grin). It is a very pleasant experience and has a short learning curve if you already know web development.


I’ve been thinking about it for a while. Time is my enemy right now. Any pointers on how to quickly get started? This has been on my stale tab for quite a while now. :laughing:


Using the app generator built-in package to create a base app is the usual way to start. You would remove the key binding and view and just start the package at boot time. Then you would need to hook the save dialog and replace it.

Or, if you don’t like hacking core, you could put up a normal warning dialog box before the save with Cancel and Continue buttons. Continue would then proceed to the save dialog. The interface to git is in the api and is fully supported.

I would be glad to help if you wished. I have helped others.


qq: Is there a way to automatically load the package during the loading of atom itself? All I’m seeing in the API is that the package needs to be activated by either command or key-binding?


If you don’t specify activationCommands in package.json, then it will activate when Atom starts.


Which unfortunately slows down atom’s loading which is a serious Atom problem. But if it is needed then it is needed. Your package might not slow down the load if it doesn’t do much in the beginning.

There is a trick to only fire a timeout when you first load and then do all the initialization on the timeout. It just means you wouldn’t get the warning in the very beginning, which might not be a problem.


I’ll try this again tonight. I thought I tried without activationCommands but it wasn’t displaying my log that was in activate method.


I started working on something like this a while back. My goal was to save the workspace for each branch, and then restore when the branch changed.

I had a proof of concept working, but Atoms APIs changed a little too quick and their documentation was lacking in some areas I was trying to use (mostly hooking into events), so this is almost surely broken now and I haven’t touched it for some time (although with 1.0 approaching I think it may be worth getting into again). In any case, it may help guide you on how to get started and use the git API.


This is the core file, it goes in the package lib folder. Also, it’s written in javascript, as I prefer it personally over coffeescript. Hope it helps!


Hey thanks. Since this would be my first package I think I’ll be sticking with a simple indicator for now and see how that turns out. I am totally with you on choosing javascript over coffeescript though. I keep having to go lookup for syntax which hasn’t been super fun.


Doh!! For some reason I read that as activationEvents and repeatedly kept thinking that activationCommands was activationEvents. It works now. Thanks for the help. :smiley:

Trying my best to not have any perf impact on atom. But at times, I just want to see something work and perf takes a backseat. I’ll definitely need help on that one later for sure.


I’m trying to find out if there are any event that I can invoke whenever a new directory is added to the workspace. I did find the onDidOpen event but it only gets invoked whenever a file is opened in the pane. Would make my life a little easier if there was an event already defined on the API.