aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/formula.rb2
-rw-r--r--Library/Homebrew/formula_installer.rb57
-rw-r--r--Library/Homebrew/global.rb2
-rw-r--r--Library/Homebrew/keg.rb2
-rw-r--r--Library/Homebrew/test/testing_env.rb1
5 files changed, 62 insertions, 2 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 0693634f5..11a90a91b 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -142,7 +142,7 @@ class Formula
def kext_prefix; prefix+'Library/Extensions' end
# configuration needs to be preserved past upgrades
- def etc; HOMEBREW_PREFIX+'etc' end
+ def etc; HOMEBREW_GIT_ETC ? prefix+'etc' : HOMEBREW_PREFIX+'etc' end
# generally we don't want var stuff inside the keg
def var; HOMEBREW_PREFIX+'var' end
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
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index 18934c6ca..52e9149e5 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -84,6 +84,8 @@ HOMEBREW_USER_AGENT = "Homebrew #{HOMEBREW_VERSION} (Ruby #{RUBY_VERSION}-#{RUBY
HOMEBREW_CURL_ARGS = '-f#LA'
+HOMEBREW_GIT_ETC = !ENV['HOMEBREW_GIT_ETC'].nil?
+
module Homebrew extend self
include FileUtils
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 4a3fd2ddd..6a1784acf 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -114,7 +114,7 @@ class Keg < Pathname
# yeah indeed, you have to force anything you need in the main tree into
# these dirs REMEMBER that *NOT* everything needs to be in the main tree
- link_dir('etc', mode) {:mkpath}
+ link_dir('etc', mode) {:mkpath} unless HOMEBREW_GIT_ETC
link_dir('bin', mode) {:skip_dir}
link_dir('sbin', mode) {:skip_dir}
link_dir('include', mode) {:link}
diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb
index 9bc5d871f..e9532bb96 100644
--- a/Library/Homebrew/test/testing_env.rb
+++ b/Library/Homebrew/test/testing_env.rb
@@ -25,6 +25,7 @@ HOMEBREW_USER_AGENT = 'Homebrew'
HOMEBREW_WWW = 'http://example.com'
HOMEBREW_CURL_ARGS = '-fsLA'
HOMEBREW_VERSION = '0.9-test'
+HOMEBREW_GIT_ETC = false
RUBY_BIN = Pathname.new(RbConfig::CONFIG['bindir'])
RUBY_PATH = RUBY_BIN + RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']