git_etc: update based on bottle etc/var changes.

This commit is contained in:
Mike McQuaid 2013-10-05 20:39:51 +01:00
parent a9764503b2
commit a6e2245732
6 changed files with 47 additions and 37 deletions

View File

@ -165,12 +165,7 @@ class Formula
def kext_prefix; prefix+'Library/Extensions' end
# configuration needs to be preserved past upgrades
def etc
etc = HOMEBREW_PREFIX+'etc'
etc = prefix+etc if HOMEBREW_GIT_ETC
etc.extend(InstallRenamed)
etc
end
def etc; (HOMEBREW_PREFIX+'etc').extend(InstallRenamed) end
# generally we don't want var stuff inside the keg
def var; HOMEBREW_PREFIX+'var' end

View File

@ -79,9 +79,15 @@ class FormulaInstaller
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', '--all', '.'
system 'git', 'commit', '-m', "#{f.name}-#{f.version}: preinstall"
quiet_system 'git', 'checkout', '-B', "#{f.name}-preinstall"
unless quiet_system 'git', 'diff', '--exit-code', 'HEAD'
system 'git', 'add', '--all', '.'
system 'git', 'commit', '-m', "#{f.name}-#{f.version}: preinstall"
end
unless quiet_system 'git', 'rev-parse', 'master'
quiet_system 'git', 'branch', 'master'
end
end
end
@ -89,37 +95,49 @@ class FormulaInstaller
return unless quiet_system 'git', '--version'
etc = HOMEBREW_PREFIX+'etc'
keg_etc_files = Dir[f.etc+'*']
last_branch = "#{f.name}-last"
preinstall_branch = "#{f.name}-preinstall"
default_branch = "#{f.name}-default"
merged = false
etc.cd do
FileUtils.cp_r keg_etc_files, etc
system 'git', 'add', '--all', '.'
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', '--all', '.'
else
quiet_system 'git', 'checkout', '-b' 'master'
end
if quiet_system 'git', 'diff', '--exit-code', preinstall_branch
quiet_system 'git', 'branch', default_branch
quiet_system 'git', 'branch', '-D', preinstall_branch
elsif not quiet_system 'git', 'rev-parse', default_branch
quiet_system 'git', 'checkout', '-B', default_branch
quiet_system 'git', 'add', '--all', '.'
system 'git', 'commit', '-m', "#{f.name}-#{f.version}: default"
quiet_system 'git', 'branch', '-D', preinstall_branch
else
previous_default_branch = `git rev-parse #{default_branch}`.strip
quiet_system 'git', 'checkout', '-B', default_branch
quiet_system 'git', 'add', '--all', '.'
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
default_unchanged = quiet_system('git', 'diff', '--exit-code', \
previous_default_branch)
if default_unchanged
system 'git', 'reset', '--hard', previous_default_branch
end
quiet_system 'git', 'checkout', 'master'
quiet_system 'git', 'reset', '--hard', preinstall_branch
unless default_unchanged
merge_ff = quiet_system 'git', 'merge', '--ff-only', '--no-edit',
'-X', 'ours', default_branch
unless merge_ff
merged = true
system 'git', 'merge', '--no-ff', '--no-edit',
'-X', 'ours', default_branch
end
end
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 reverse this merge: git reset --hard #{preinstall_branch}"
puts "To restore defaults: git reset --hard #{default_branch}"
end
end
@ -175,7 +193,7 @@ class FormulaInstaller
@@attempted << f
#git_etc_preinstall if HOMEBREW_GIT_ETC
git_etc_preinstall if ENV['HOMEBREW_GIT_ETC']
@poured_bottle = false
@ -208,7 +226,7 @@ class FormulaInstaller
opoo "#{f.name} post_install failed. Rerun with `brew postinstall #{f.name}`."
end
#git_etc_postinstall if HOMEBREW_GIT_ETC
git_etc_postinstall if ENV['HOMEBREW_GIT_ETC']
opoo "Nothing was installed to #{f.prefix}" unless f.installed?
end

View File

@ -84,8 +84,6 @@ 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

View File

@ -15,7 +15,7 @@ module InstallRenamed
private
def append_default_if_different src, dst
if File.file? dst and !FileUtils.identical?(src, dst) and !HOMEBREW_GIT_ETC
if File.file? dst and !FileUtils.identical?(src, dst) and !ENV['HOMEBREW_GIT_ETC']
dst += ".default"
end
dst

View File

@ -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} unless HOMEBREW_GIT_ETC
link_dir('etc', mode) {:mkpath}
link_dir('bin', mode) {:skip_dir}
link_dir('sbin', mode) {:skip_dir}
link_dir('include', mode) {:link}

View File

@ -25,7 +25,6 @@ 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']