Homebrew / legacy-homebrew

💀 The former home of Homebrew/homebrew (deprecated)
https://brew.sh
26.99k stars 11.36k forks source link

interrupted git download leaves git in broken state #16520

Closed mblakele closed 11 years ago

mblakele commented 11 years ago

If brew is interrupted while updating git, it leaves git unlinked - and in my environment unlinkable. Can anything be done to make this more robust? Maybe wait to unlink the old version until the new version is ready?

$ brew --version
0.9.3
$ brew update && brew outdated && brew upgrade
Updated Homebrew from 0a868aba to 9e4d2ca3.
==> Updated Formulae
git   go        nzbget    vcftools  wxmac
git (1.7.10, 1.7.10.1, 1.7.10.2, 1.7.10.3, 1.7.10.4, 1.7.11.1, 1.7.11.2, 1.7.11.3, 1.7.11.4, 1.7.11.5, 1.7.12, 1.7.12.1, 1.7.12.2, 1.7.12.3, 1.7.12.4, 1.8.0, 1.8.0.1 < 1.8.0.2)
==> Upgrading git
==> Downloading http://git-core.googlecode.com/files/git-1.8.0.2.tar.gz
###############################################################           88.3%

At this point the wifi goes down, and brew hangs. As it exits I see:

Warning: Could not link git. Unlinking...

Now any git-dependent brew functions are broken.

$ brew update && brew outdated && brew upgrade
error: Malformed value for push.default: simple
error: Must be one of nothing, matching, tracking or current.
fatal: bad config file line 18 in /Users/mblakele/.gitconfig
Error: Failure while executing: git checkout -q master 

All these errors appear to come from git not working. Maybe the doctor can help?

$ brew doctor
fatal: bad config file line 18 in /Users/mblakele/.gitconfig
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:

    git

OK, but the suggested fix doesn't work:

$ brew link git Error: git has multiple installed versions

Instead the fix seems to be to explicitly switch to the last known version.

$ brew switch git 1.8.0.1
Cleaning /usr/local/Cellar/git/1.7.10
Cleaning /usr/local/Cellar/git/1.7.10.1
Cleaning /usr/local/Cellar/git/1.7.10.2
Cleaning /usr/local/Cellar/git/1.7.10.3
Cleaning /usr/local/Cellar/git/1.7.10.4
Cleaning /usr/local/Cellar/git/1.7.11.1
Cleaning /usr/local/Cellar/git/1.7.11.2
Cleaning /usr/local/Cellar/git/1.7.11.3
Cleaning /usr/local/Cellar/git/1.7.11.4
Cleaning /usr/local/Cellar/git/1.7.11.5
Cleaning /usr/local/Cellar/git/1.7.12
Cleaning /usr/local/Cellar/git/1.7.12.1
Cleaning /usr/local/Cellar/git/1.7.12.2
Cleaning /usr/local/Cellar/git/1.7.12.3
Cleaning /usr/local/Cellar/git/1.7.12.4
Cleaning /usr/local/Cellar/git/1.8.0
Cleaning /usr/local/Cellar/git/1.8.0.1
203 links created for /usr/local/Cellar/git/1.8.0.1

It looks like I should run 'brew cleanup' more often. But can anything be done to make this more robust?

samueljohn commented 11 years ago

Indeed, looks like a place to improve. Some check if git is sane.

However, you had a lot of older kegs (i.e. versions) installed in the Cellar, which is another issue brew could improve. Usually brew cleanup helps a bit with removing old versions that are not needed.

I have proposed earlier that brew link git should use the one with the highest version number (and issue a small warning, because some version numbering schemes suck).

If find it strange that fatal: bad config file line 18 in /Users/mblakele/.gitconfig claims the config file is "bad"... Can you gist.github.com you .gitconfig?

jacknagel commented 11 years ago

The reason is that because your Homebrew git is not linked, it is using the Xcode-provided git which is too old to recognize the "simple" push option.

mblakele commented 11 years ago

I've run brew cleanup and added it to my daily-update script. Not sure why it wasn't there before.

My .gitconfig is 17 lines long, and hasn't changed in 33 days. Normally brew has no problem with it, and I think that's just a symptom of git not working.

$ wc -l /Users/mblakele/.gitconfig
      17 /Users/mblakele/.gitconfig
$ tail /Users/mblakele/.gitconfig
        branch = auto
        status = auto
        diff = auto
[alias]
        st = status
        ci = commit
        co = checkout
        br = branch
[push]
        default = simple
jacknagel commented 11 years ago

There's not really anything I can think of that can improve this. Homebrew can only relink after failed installs if there is only one other keg (in other words, if there is more than one it doesn't know which one to relink). Coupled with what I noted above, you will see issues until you relink a git that is capable of understanding push.default = simple.

jacknagel commented 11 years ago

Closing because this isn't something we can control. The risk you take when using cutting-edge git features is that older git won't understand them.