From 9ac477b07c6569ae663f33e0a864b49f0b4ae9bd Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 11 Sep 2012 20:55:16 -0400 Subject: [PATCH] brew unpack: support -gpf -g sets up git repo. -f forces even if already there. I found these useful. --- Library/Contributions/cmds/brew-unpack.rb | 36 ++++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Library/Contributions/cmds/brew-unpack.rb b/Library/Contributions/cmds/brew-unpack.rb index d25d389505..cee1d0ba30 100755 --- a/Library/Contributions/cmds/brew-unpack.rb +++ b/Library/Contributions/cmds/brew-unpack.rb @@ -30,7 +30,7 @@ class Formula # so that paching only happens if the user asks. alias do_patch patch def patch - if ARGV.include? '--patch' + if ARGV.flag? '--patch' # Yes Ruby, we are about to redefine a constant. Just breathe. orig_v = $VERBOSE; $VERBOSE = nil Formula.const_set 'DATA', ScriptDataReader.load(path) @@ -48,19 +48,18 @@ end module Homebrew extend self def unpack unpack_usage = <<-EOS -Usage: brew unpack [--patch] [--destdir=path/to/extract/in] +Usage: brew unpack [-pg] [--destdir=path/to/extract/in] Unpack formulae source code for inspection. Formulae archives will be extracted to subfolders inside the current working -directory or a directory specified by `--destdir`. If the `--patch` option is -supplied, patches will also be downloaded and applied. +directory or a directory specified by `--destdir`. If the `-p` option is +supplied, patches will also be downloaded and applied. If the `-g` option is +specified a git repository is created and all files added so that you can diff +changes. EOS - if ARGV.empty? - puts unpack_usage - exit 0 - end + abort unpack_usage if ARGV.empty? formulae = ARGV.formulae raise FormulaUnspecifiedError if formulae.empty? @@ -78,11 +77,26 @@ supplied, patches will also be downloaded and applied. formulae.each do |f| # Create a nice name for the stage folder. stage_dir = unpack_dir + [f.name, f.version].join('-') - raise "Destination #{stage_dir} allready exists!" if stage_dir.exist? + if stage_dir.exist? + raise "Destination #{stage_dir} allready exists!" unless ARGV.force? + rm_rf stage_dir + end + + oh1 "Unpacking #{f.name} to: #{stage_dir}" + ENV['VERBOSE'] = '1' # show messages about tar f.brew do - oh1 "Unpacking #{f.name} to: #{stage_dir}" - cp_r Dir.getwd, stage_dir + cd Dir['*'][0] if Dir['*'].one? + mv getwd, stage_dir + end + ENV['VERBOSE'] = nil + + if ARGV.switch? 'g' + ohai "Setting up git repository" + cd stage_dir + system "git init -q" + system "git add -A" + system 'git commit -qm"Vanilla"' end end end