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 def kext_prefix; prefix+'Library/Extensions' end
# configuration needs to be preserved past upgrades # configuration needs to be preserved past upgrades
def etc def etc; (HOMEBREW_PREFIX+'etc').extend(InstallRenamed) end
etc = HOMEBREW_PREFIX+'etc'
etc = prefix+etc if HOMEBREW_GIT_ETC
etc.extend(InstallRenamed)
etc
end
# generally we don't want var stuff inside the keg # generally we don't want var stuff inside the keg
def var; HOMEBREW_PREFIX+'var' end def var; HOMEBREW_PREFIX+'var' end

View File

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

View File

@ -84,8 +84,6 @@ HOMEBREW_USER_AGENT = "Homebrew #{HOMEBREW_VERSION} (Ruby #{RUBY_VERSION}-#{RUBY
HOMEBREW_CURL_ARGS = '-f#LA' HOMEBREW_CURL_ARGS = '-f#LA'
HOMEBREW_GIT_ETC = !ENV['HOMEBREW_GIT_ETC'].nil?
module Homebrew extend self module Homebrew extend self
include FileUtils include FileUtils

View File

@ -15,7 +15,7 @@ module InstallRenamed
private private
def append_default_if_different src, dst 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" dst += ".default"
end end
dst dst

View File

@ -114,7 +114,7 @@ class Keg < Pathname
# yeah indeed, you have to force anything you need in the main tree into # 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 # 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('bin', mode) {:skip_dir}
link_dir('sbin', mode) {:skip_dir} link_dir('sbin', mode) {:skip_dir}
link_dir('include', mode) {:link} link_dir('include', mode) {:link}

View File

@ -25,7 +25,6 @@ HOMEBREW_USER_AGENT = 'Homebrew'
HOMEBREW_WWW = 'http://example.com' HOMEBREW_WWW = 'http://example.com'
HOMEBREW_CURL_ARGS = '-fsLA' HOMEBREW_CURL_ARGS = '-fsLA'
HOMEBREW_VERSION = '0.9-test' HOMEBREW_VERSION = '0.9-test'
HOMEBREW_GIT_ETC = false
RUBY_BIN = Pathname.new(RbConfig::CONFIG['bindir']) RUBY_BIN = Pathname.new(RbConfig::CONFIG['bindir'])
RUBY_PATH = RUBY_BIN + RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT'] RUBY_PATH = RUBY_BIN + RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']