Yesterday I had the weirdest experience with mix.
TL;DR: I decided to ^C during "mix deps.get" and that resulted in a corrupted project.
Here's a partial reconstruction of the events. I believe I was using v0.12.5 at the time.
λ mix deps.get* Getting cowboy (git://github.com/extend/cowboy.git)
Cloning into '/Users/alco/home/projects/beamie/deps/cowboy'...remote: Reusing existing pack: 5948, done.
remote: Counting objects: 38, done.remote: Compressing objects: 100% (38/38), done.
^Cceiving objects: 20% (1243/5986), 892.00 KiB | 415 KiB/s BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution^C% ~/home/projects/beamie/ master*
At this point I figured out I shouldn't have cancelled the fetch, so I issued the command once again:
λ mix deps.get
* Updating cowboy (git://github.com/extend/cowboy.git)warning: no common commits
[...]From git://github.com/extend/cowboy
* branch HEAD -> FETCH_HEADerror: Your local changes to the following files would be overwritten by checkout:
lib/beamie/templates/play.html.eexPlease, commit your changes or stash them before you can switch branches.
Aborting** (Mix) Command `git checkout --quiet df818625545d565b8b76fbc445063a4822114b93` failed
Now this was weird. I don't remember ever seeing that message before. Well, better try and do what it says. I committed the changes and tried to fetch deps again:
Everything seems to be fine except for the prompt on the last line: it switched the current branch from master to some commit. But I didn't notice it at first and tried running the project:
λ mix run --no-halt
** (Mix) Could not find a Mix.Project, please ensure a mix.exs file is available
WAT.
I should mention that all of this was happening at around 4 AM, so it all started to feel doubly surreal.
Let's `ls` the current directory:
λ ltotal 200-rw-r--r--@ 1 alco staff 6148 Apr 18 18:11 .DS_Store
drwxr-xr-x 14 alco staff 476 Apr 22 05:15 .git-rw-r--r-- 1 alco staff 123 Apr 22 05:14 .gitignore
-rw-r--r-- 1 alco staff 992 Apr 22 05:14 AUTHORS-rw-r--r-- 1 alco staff 24644 Apr 22 05:14 CHANGELOG.md
-rw-r--r-- 1 alco staff 5498 Apr 22 05:14 CONTRIBUTING.md-rw-r--r-- 1 alco staff 13437 Apr 13 12:47 Elixir.Beamie.CodeStore
-rw-r--r-- 1 alco staff 757 Apr 22 05:14 LICENSE-rw-r--r-- 1 alco staff 583 Apr 22 05:14 Makefile
-rw-r--r-- 1 alco staff 1080 Apr 22 05:14 README.md-rw-r--r-- 1 alco staff 749 Apr 22 05:14 ROADMAP.md
drwxr-xr-x 3 alco staff 102 Mar 10 21:36 _builddrwxr-xr-x 2 alco staff 68 Nov 12 19:37 db
drwxr-xr-x 5 alco staff 170 Apr 22 05:14 depsdrwxr-xr-x 4 alco staff 136 Apr 22 05:14 doc
drwxr-xr-x 11 alco staff 374 Apr 17 04:20 docker-rw-r--r-- 1 alco staff 7286 Apr 22 05:14 erlang.mk
drwxr-xr-x 20 alco staff 680 Apr 22 05:14 examplesdrwxr-xr-x 26 alco staff 884 Apr 22 05:14 guide
drwxr-xr-x 18 alco staff 612 Apr 22 05:14 manual-rw-r--r-- 1 alco staff 541 Apr 22 05:14 mix.lock
drwxr-xr-x 3 alco staff 102 Apr 22 05:14 priv-rw-r--r-- 1 alco staff 152 Apr 22 05:14 rebar.config
drwxr-xr-x 24 alco staff 816 Apr 22 05:14 srcdrwxr-xr-x 11 alco staff 374 Apr 22 05:14 test
This is definitely not my project except for some left over files (which weren't delete because they were .gitignored or untracked in my project).
The fun continues:
λ git lgdf81862 (HEAD) Merge branch 'patch-1' of git://github.com/alco/cowboy
62a4791 Fix link to the Ranch guide in getting started1c8b6e3 Fix grammar in "how it looks like"
5a25c7f Add link to cowboy_spdy function reference in indexdb52494 Update Cowboy to 0.9.0
What actually happened was that a commit from cowboy dep was somehow checked out into my project's directory. Also notice the top commit: this one's from Nov 2013. I didn't notice it yesterday, but even now I have no idea how it got there.
I also should mention that this project is not yet published, I only keep my "projects" directory synced to SpiderOak and Wuala. So I turned off both of them to prevent possible data loss.
After a little bit of panicking, I tried `git reflog`:
λ git reflog
df81862 HEAD@{0}: checkout: moving from master to df818625545d565b8b76fbc445063a4822114b93
d658ece HEAD@{1}: commit: Commit changes
[...]
Luckily, it wasn't damaged. Moreover, I was able to check out back to my project's master (albeit with hurdles):
λ git co mastererror: The following untracked working tree files would be overwritten by checkout:
mix.lockPlease move or remove them before you can switch branches.
Abortingλ rm mix.lock
λ git co masterWarning: you are leaving 1044 commits behind, not connected to
any of your branches: df81862 Merge branch 'patch-1' of git://github.com/alco/cowboy
62a4791 Fix link to the Ranch guide in getting started 1c8b6e3 Fix grammar in "how it looks like"
5a25c7f Add link to cowboy_spdy function reference in index ... and 1040 more.
If you want to keep them by creating a new branch, this may be a good time
to do so with: git branch new_branch_name df818625545d565b8b76fbc445063a4822114b93
Switched to branch 'master'
Leaving 1044 commits behind is not something I do on a daily basis, that's for sure.
Now, every time I repeat "mix deps.get" I get this:
Notice that it checked out back to that mysterious commit from cowboy.
After that, I checked out back to master and cloned the project locally to another directory. The clone seems to be fine and I have been developing in it since then.
---
Somehow cowboy's url got in there. But that can't be causing the issue. In any case, when I restore the config back to it's (supposed) original, "mix deps.get" still checks out cowboy to the current directory.
That's as far as I got in my investigation so far.
I hope you enjoyed the narrative.
--
Best regards
Alexei Sholik