aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Contributions
diff options
context:
space:
mode:
authorJack Nagel2014-05-17 17:12:40 -0500
committerJack Nagel2014-05-17 17:12:40 -0500
commit534ec78e32e93e64566ebca2af6b8ad5b5035d75 (patch)
treeacd0b5d291e684e3c2763158ade16229aa145e7a /Library/Contributions
parentd612a58c3086c6ba11fb796258a708cb71354be2 (diff)
downloadhomebrew-534ec78e32e93e64566ebca2af6b8ad5b5035d75.tar.bz2
Move brew-unpack to core
Diffstat (limited to 'Library/Contributions')
-rw-r--r--Library/Contributions/brew_bash_completion.sh12
-rwxr-xr-xLibrary/Contributions/cmd/brew-unpack.rb100
-rw-r--r--Library/Contributions/manpages/brew.1.md12
3 files changed, 24 insertions, 100 deletions
diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh
index 7d3fc595f..6f97935f0 100644
--- a/Library/Contributions/brew_bash_completion.sh
+++ b/Library/Contributions/brew_bash_completion.sh
@@ -370,6 +370,17 @@ _brew_uninstall ()
__brew_complete_installed
}
+_brew_unpack ()
+{
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ case "$cur" in
+ --*)
+ __brewcomp "--git --patch --destdir="
+ return
+ ;;
+ esac
+ __brew_complete_formulae
+}
_brew_update ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -520,6 +531,7 @@ _brew ()
switch) _brew_switch ;;
tap) _brew_complete_tap ;;
uninstall|remove|rm) _brew_uninstall ;;
+ unpack) _brew_unpack ;;
unpin) __brew_complete_formulae ;;
untap) __brew_complete_tapped ;;
update) _brew_update ;;
diff --git a/Library/Contributions/cmd/brew-unpack.rb b/Library/Contributions/cmd/brew-unpack.rb
deleted file mode 100755
index 4ff19b0e1..000000000
--- a/Library/Contributions/cmd/brew-unpack.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-require 'formula'
-
-require 'stringio'
-module ScriptDataReader
- # This module contains a method for extracting the contents of DATA from a
- # Ruby file other than the script containing the currently executing
- # function. Many thanks to Glenn Jackman's Stackoverflow answer which
- # provided this code:
- #
- # http://stackoverflow.com/questions/2156629/can-i-access-the-data-from-a-required-script-in-ruby/2157556#2157556
- def self.load(filename)
- data = StringIO.new
- File.open(filename) do |f|
- begin
- line = f.gets
- end until line.nil? or line.match(/^__END__$/)
- while line = f.gets
- data << line
- end
- end
- data.rewind
- data
- end
-end
-
-module UnpackPatch
- def patch
- return unless ARGV.flag? "--patch"
-
- begin
- old_verbose = $VERBOSE
- $VERBOSE = nil
- Object.const_set "DATA", ScriptDataReader.load(path)
- ensure
- $VERBOSE = old_verbose
- end
-
- super
- end
-end
-
-module Homebrew extend self
- def unpack_usage; <<-EOS.undent
- 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 `-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
- end
-
- def unpack
- abort unpack_usage if ARGV.empty?
-
- formulae = ARGV.formulae
- raise FormulaUnspecifiedError if formulae.empty?
-
- if (dir = ARGV.value('destdir')).nil?
- unpack_dir = Pathname.pwd
- else
- unpack_dir = Pathname.new(dir)
- unpack_dir.mkpath unless unpack_dir.exist?
- end
-
- raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real?
-
- formulae.each do |f|
- f.extend(UnpackPatch)
-
- # Create a nice name for the stage folder.
- stage_dir = unpack_dir + [f.name, f.version].join('-')
-
- if stage_dir.exist?
- raise "Destination #{stage_dir} already 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 { cp_r getwd, stage_dir }
- 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", "-q", "-m", "brew-unpack"
- end
- end
- end
-end
-
-# Here is the actual code that gets run when `brew` loads this external
-# command.
-Homebrew.unpack
diff --git a/Library/Contributions/manpages/brew.1.md b/Library/Contributions/manpages/brew.1.md
index 9177fffc2..22d8dbf8f 100644
--- a/Library/Contributions/manpages/brew.1.md
+++ b/Library/Contributions/manpages/brew.1.md
@@ -352,6 +352,18 @@ Note that these flags should only appear after a command.
* `unlinkapps [--local]`:
Removes links created by `brew linkapps`.
+ * `unpack [--git|--patch] [--destdir=<path>]` <formulae>:
+
+ Unpack the source files for <formulae> into subdirectories of the current
+ working directory. If `--destdir=<path>` is given, the subdirectories will
+ be created in the directory named by `<path>` instead.
+
+ If `--patch` is passed, patches for <formulae> will be applied to the
+ unpacked source.
+
+ If `--git` is passed, a Git repository will be initalized in the unpacked
+ source. This is useful for creating patches for the software.
+
* `unpin` <formulae>:
Unpin <formulae>, allowing them to be upgraded by `brew upgrade`. See also
`pin`.