brew updateでエラーが大量に出たときの対処

いつからかは分からないが、brew updateでエラーが大量に出るようになった。

```
MBA:~ yshino271$ brew update
Library/Aliases: needs merge
Library/Formula: needs merge
Library/Aliases: needs merge
Library/Formula: needs merge
Library/Aliases: unmerged (a6d560e69e2732d28a2f8193868591a8344d5595)
Library/Formula: unmerged (9028792ad53d2732a9b1c28dd305c3cd1452d5cd)
fatal: git-write-tree: error building trees
Cannot save the current index state
error: 'Library/Aliases' appears as both a file and as a directory
error: Library/Aliases: cannot drop to stage #0
warning: unable to unlink Library/Formula: Operation not permitted
Adding Library/Formula/zzz.rb
Adding Library/Formula/zzuf.rb
Adding Library/Formula/zxcc.rb
Adding Library/Formula/zurl.rb
Adding Library/Formula/zsync.rb
〜〜〜省略〜〜〜
Adding Library/Aliases/Secret Rabbit Code
Adding Library/Aliases/4store
Adding Library/Aliases/2ping
Adding Library/Aliases/0mq
Adding Library/Aliases/0install
CONFLICT (directory/file): There is a directory with name Library/Aliases in HEAD. Adding Library/Aliases as Library/Aliases~origin_master_1
Automatic merge failed; fix conflicts and then commit the result.
To restore the stashed changes to /usr/local run:
  'cd /usr/local && git stash pop'
Already up-to-date.
```

brew doctorもいろいろ出る。

```
MBA:~ yshino271$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: Suspicious git origin remote found.

With a non-standard origin, Homebrew won't pull updates from
the main repository. The current git origin is:
  https://github.com/Homebrew/brew.git

Unless you have compelling reasons, consider setting the
origin remote to point at the main repository, located at:
  https://github.com/Homebrew/homebrew.git

Warning: You have uncommitted modifications to Homebrew
If this is a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
    cd /usr/local/Library && git stash && git clean -d -f
```

brew doctorの指示に従っても治らない。

```
MBA:~ yshino271$ cd /usr/local/Library && git stash && git clean -d -f
Library/Aliases: needs merge
Library/Formula: needs merge
Library/Aliases: needs merge
Library/Formula: needs merge
Library/Aliases: unmerged (a6d560e69e2732d28a2f8193868591a8344d5595)
Library/Formula: unmerged (9028792ad53d2732a9b1c28dd305c3cd1452d5cd)
fatal: git-write-tree: error building trees
Cannot save the current index state
```

なのでここを参考に対処。
https://github.com/Homebrew/legacy-homebrew/issues/5128

```
MBA:Library yshino271$ cd /usr/local
MBA:local yshino271$ git remote add origin git://github.com/mxcl/homebrew.git
fatal: remote origin already exists.
MBA:local yshino271$ git fetch origin
MBA:local yshino271$ git reset --hard origin/master
error: 'Library/Aliases' appears as both a file and as a directory
error: Library/Aliases: cannot drop to stage #0
HEAD is now at 11d47e8 boneyard-formula-pr: add new command.
```

brew doctorは通るようになった。

```
MBA:local yshino271$ brew doctor
Your system is ready to brew.
```

でも、brew updateはまだいけてない。

```
MBA:local yshino271$ brew update
Library/Formula: needs merge
Library/Formula: needs merge
fatal: You need to resolve your current index first
Cannot save the current worktree state
To restore the stashed changes to /usr/local run:
  'cd /usr/local && git stash pop'
Already up-to-date.
```

git stash popしてもダメ。

```
MBA:local yshino271$ cd /usr/local && git stash pop
Library/Aliases~origin_master already exists, no checkout
Library/Aliases~origin_master_0 already exists, no checkout
Library/Aliases~origin_master_1 already exists, no checkout
Library/Formula~origin_master already exists, no checkout
Library/Formula~origin_master_0 already exists, no checkout
Library/Formula~origin_master_1 already exists, no checkout
Could not restore untracked files from stash
```

```
MBA:local yshino271$ brew update
To restore the stashed changes to /usr/local run:
  'cd /usr/local && git stash pop'
Already up-to-date.
```

もういいやとbrew upgrade --all。

```
MBA:local yshino271$ brew upgrade --all
==> Upgrading 6 outdated packages, with result:
gdbm 1.12, libgpg-error 1.22, libksba 1.3.4, openssl 1.0.2h_1, pkg-config 0.29.1, sqlite 3.13.0
==> Upgrading gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.12.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gdbm-1.12.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/gdbm/1.12: 18 files, 490.7K
==> Upgrading libgpg-error
==> Downloading https://homebrew.bintray.com/bottles/libgpg-error-1.22.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libgpg-error-1.22.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libgpg-error/1.22: 19 files, 427.4K
==> Upgrading libksba
==> Downloading https://homebrew.bintray.com/bottles/libksba-1.3.4.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libksba-1.3.4.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libksba/1.3.4: 13 files, 357.2K
==> Upgrading openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2h_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2h_1.el_capitan.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2h_1: 1,691 files, 12M
==> Upgrading pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.1.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.29.1: 10 files, 627.2K
==> Upgrading sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.13.0.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring sqlite-3.13.0.el_capitan.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include

==> Summary
🍺  /usr/local/Cellar/sqlite/3.13.0: 10 files, 2.9M
```

出なくなった。

```
MBA:local yshino271$ brew update
Already up-to-date.
```