diff options
| author | Mike McQuaid | 2013-09-01 16:03:02 +0100 |
|---|---|---|
| committer | Mike McQuaid | 2013-09-07 13:39:43 +0100 |
| commit | ab20ed0bc2be02bb26bdd465bc260e2a4f526c9f (patch) | |
| tree | 1c21ada40e5a030dd8cd304357dde6220b4d3c33 /Library/Homebrew/formula_installer.rb | |
| parent | 3e7da6b16e81ecf76bce73d871807ed7228fb7e0 (diff) | |
| download | brew-ab20ed0bc2be02bb26bdd465bc260e2a4f526c9f.tar.bz2 | |
Optionally use git to keep brew etc versioned.
Still in alpha state.
Handles defaults and merging changes with new versions.
Enable by setting the HOMEBREW_GIT_ETC environment variable.
Closes Homebrew/homebrew#15751.
Closes Homebrew/homebrew#17713.
Diffstat (limited to 'Library/Homebrew/formula_installer.rb')
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 789e3b5aa..b2de046d0 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -71,6 +71,58 @@ class FormulaInstaller raise end + def git_etc_preinstall + return unless quiet_system 'git', '--version' + + etc = HOMEBREW_PREFIX+'etc' + etc.cd do + quiet_system 'git', 'init' unless (etc+'.git').directory? + quiet_system 'git', 'checkout', '-B', "#{f.name}-last" + system 'git', 'add', '.' + system 'git', 'commit', '-m', "#{f.name}-#{f.version}: preinstall" + end + end + + def git_etc_postinstall + return unless quiet_system 'git', '--version' + + etc = HOMEBREW_PREFIX+'etc' + keg_etc_files = Dir[f.etc+'*'] + last_branch = "#{f.name}-last" + default_branch = "#{f.name}-default" + merged = false + etc.cd do + FileUtils.cp_r keg_etc_files, etc + + system 'git', 'add', '.' + if quiet_system 'git', 'diff', '--exit-code', default_branch + quiet_system 'git', 'reset', '--hard' + else + if quiet_system 'git', 'rev-parse', 'master' + quiet_system 'git', 'checkout', '-f', 'master' + FileUtils.cp_r keg_etc_files, etc + quiet_system 'git', 'add', '.' + else + quiet_system 'git', 'checkout', '-b' 'master' + end + system 'git', 'commit', '-m', "#{f.name}-#{f.version}: default" + quiet_system 'git', 'branch', '-f', default_branch + + merged = true unless quiet_system 'git' 'merge-base', '--is-ancestor', + last_branch, 'master' + system 'git', 'merge', '--no-ff', '--no-edit', + '-X', 'theirs', last_branch + end + + if merged + ohai "Configuration Files" + puts "Your configuration files for #{f.name} in etc were merged:" + puts "To reverse this merge: git reset --hard #{last_branch}" + puts "To restore defaults: git reset --hard #{default_branch}" + end + end + end + def install # not in initialize so upgrade can unlink the active keg before calling this # function but after instantiating this class so that it can avoid having to @@ -110,7 +162,10 @@ class FormulaInstaller @@attempted << f + git_etc_preinstall if HOMEBREW_GIT_ETC + @poured_bottle = false + begin if pour_bottle? true pour @@ -136,6 +191,8 @@ class FormulaInstaller opoo "#{f.name} post_install failed. Rerun with `brew postinstall #{f.name}`." end + git_etc_postinstall if HOMEBREW_GIT_ETC + opoo "Nothing was installed to #{f.prefix}" unless f.installed? end |
