How mix trashed my project's git config

376 views
Skip to first unread message

Alexei Sholik

unread,
Apr 22, 2014, 7:51:02 PM4/22/14
to elixir-lang-ta.
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_HEAD
error: Your local changes to the following files would be overwritten by checkout:
    lib/beamie/templates/play.html.eex
Please, 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:

λ mix deps.get
* Updating cowboy (git://github.com/extend/cowboy.git)
From git://github.com/extend/cowboy
 * branch            HEAD       -> FETCH_HEAD
* Getting gproc (git://github.com/esl/gproc.git)
Cloning into '/Users/alco/home/projects/beamie/deps/gproc'...
[...]
* Getting jazz (git://github.com/meh/jazz.git)
Cloning into '/Users/alco/home/projects/beamie/deps/jazz'...
[...]
~/home/projects/beamie/ df81862*

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:

λ l
total 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 _build
drwxr-xr-x   2 alco  staff     68 Nov 12 19:37 db
drwxr-xr-x   5 alco  staff    170 Apr 22 05:14 deps
drwxr-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 examples
drwxr-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 src
drwxr-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 lg
df81862 (HEAD) 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
db52494 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 master
error: The following untracked working tree files would be overwritten by checkout:
    mix.lock
Please move or remove them before you can switch branches.
Aborting

λ rm mix.lock

λ git co master
Warning: 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:

λ mix deps.get
* Updating cowboy (git://github.com/extend/cowboy.git)
From git://github.com/extend/cowboy
 * branch            HEAD       -> FETCH_HEAD
~/home/projects/beamie/ df81862*

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.

---

Today I tried to figure out what is actually wrong with the old project's dir. I used DiffMerge to compare the contents of two directories and the only significant change appears to be in .git/config:

https://www.dropbox.com/s/rc5q849if4f2330/Screen%20Shot%202014-04-23%20at%2002.13.30.png

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

José Valim

unread,
Apr 23, 2014, 2:12:46 AM4/23/14
to elixir-l...@googlegroups.com
Oh wow, thanks for the narrative Alco. If you have any way to reproduce the issue, please let us know, and we will try to find a mechanism to avoid it!



José Valim
Skype: jv.ptec
Founder and Lead Developer


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages