Skip to content
Browse files

brew unpack: support -gpf

-g sets up git repo. -f forces even if already there. I found these useful.
  • Loading branch information...
1 parent c516d27 commit 80d6be3303701072fb1fb905107951fe73754c46 @mxcl mxcl committed
Showing with 25 additions and 11 deletions.
  1. +25 −11 Library/Contributions/cmds/brew-unpack.rb
36 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 @@ def fails_with_llvm?; false; end
module Homebrew extend self
def unpack
unpack_usage = <<-EOS
-Usage: brew unpack [--patch] [--destdir=path/to/extract/in] <formulae ...>
+Usage: brew unpack [-pg] [--destdir=path/to/extract/in] <formulae ...>
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
- 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 @@ def unpack
formulae.each do |f|
# Create a nice name for the stage folder.
stage_dir = unpack_dir + [, 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 #{} to: #{stage_dir}"
+ ENV['VERBOSE'] = '1' # show messages about tar
f.brew do
- oh1 "Unpacking #{} 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"'

0 comments on commit 80d6be3

Please sign in to comment.
Something went wrong with that request. Please try again.