Skip to content

Commit

Permalink
Prevent tapped symlinks showing up in git status
Browse files Browse the repository at this point in the history
The symlinks taps write to Formula show up in git status, but this trick prevents this. brew-(un)tap maintain a .gitignore in Formula that contains all the symlinks brew-tap creates.

We add the .gitignore to the root .gitignore and TADA! Magic.
  • Loading branch information
mxcl committed Mar 16, 2012
1 parent fb13b6a commit a05a5fc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.DS_Store
/Library/LinkedKegs
/Library/Taps
/Library/Formula/.gitignore
15 changes: 14 additions & 1 deletion Library/Homebrew/cmd/tap.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'tempfile'

HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library"

module Homebrew extend self
Expand All @@ -19,12 +21,23 @@ def install_tap user, repo
raise "Already tapped!" if tapd.directory?
abort unless system "git clone https://github.com/#{user}/homebrew-#{repo} #{tapd}"

gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []

cd HOMEBREW_LIBRARY/"Formula"
tapd.find_formula do |relative_pathname|
# using the system ln is the only way to get relative symlinks
system "ln -s ../Taps/#{user}-#{repo}/#{relative_pathname} 2>/dev/null"
opoo "#{relative_pathname.basename(".rb")} conflicts" unless $?.success?
if $?.success?
gitignores << relative_pathname.basename.to_s
else
opoo "#{relative_pathname.basename, ".rb"} conflicts"
end
end

tf = Tempfile.new("brew-tap")
tf.write(gitignores.uniq.join("\n"))
tf.close
mv tf.path, "#{HOMEBREW_PREFIX}/Library/Formula/.gitignore"
end

private
Expand Down
13 changes: 11 additions & 2 deletions Library/Homebrew/cmd/untap.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'cmd/tap' # for Pathname.recursive_formula
require 'tempfile'

module Homebrew extend self
def untap
Expand All @@ -7,11 +8,19 @@ def untap

raise "No such tap!" unless tapd.directory?

gitignores = (HOMEBREW_PREFIX/"Library/Formula/.gitignore").read.split rescue []

tapd.find_formula do |pn|
pn = HOMEBREW_REPOSITORY/"Library/Formula"/pn.basename
bn = pn.basename.to_s
pn = HOMEBREW_REPOSITORY/"Library/Formula"/bn
pn.delete if pn.symlink? and pn.realpath.to_s =~ %r[^#{tapd.realpath}]
gitignores.delete(bn)
end

rm_rf tapd

tf = Tempfile.new("brew-untap")
tf.write(gitignores.join("\n"))
tf.close
mv tf.path, "#{HOMEBREW_PREFIX}/Library/Formula/.gitignore"
end
end

0 comments on commit a05a5fc

Please sign in to comment.