Skip to content

Commit a05a5fc

Browse files
committed
Prevent tapped symlinks showing up in git status
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.
1 parent fb13b6a commit a05a5fc

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
.DS_Store
1010
/Library/LinkedKegs
1111
/Library/Taps
12+
/Library/Formula/.gitignore

Library/Homebrew/cmd/tap.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'tempfile'
2+
13
HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library"
24

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

24+
gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
25+
2226
cd HOMEBREW_LIBRARY/"Formula"
2327
tapd.find_formula do |relative_pathname|
2428
# using the system ln is the only way to get relative symlinks
2529
system "ln -s ../Taps/#{user}-#{repo}/#{relative_pathname} 2>/dev/null"
26-
opoo "#{relative_pathname.basename(".rb")} conflicts" unless $?.success?
30+
if $?.success?
31+
gitignores << relative_pathname.basename.to_s
32+
else
33+
opoo "#{relative_pathname.basename, ".rb"} conflicts"
34+
end
2735
end
36+
37+
tf = Tempfile.new("brew-tap")
38+
tf.write(gitignores.uniq.join("\n"))
39+
tf.close
40+
mv tf.path, "#{HOMEBREW_PREFIX}/Library/Formula/.gitignore"
2841
end
2942

3043
private

Library/Homebrew/cmd/untap.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'cmd/tap' # for Pathname.recursive_formula
2+
require 'tempfile'
23

34
module Homebrew extend self
45
def untap
@@ -7,11 +8,19 @@ def untap
78

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

11+
gitignores = (HOMEBREW_PREFIX/"Library/Formula/.gitignore").read.split rescue []
12+
1013
tapd.find_formula do |pn|
11-
pn = HOMEBREW_REPOSITORY/"Library/Formula"/pn.basename
14+
bn = pn.basename.to_s
15+
pn = HOMEBREW_REPOSITORY/"Library/Formula"/bn
1216
pn.delete if pn.symlink? and pn.realpath.to_s =~ %r[^#{tapd.realpath}]
17+
gitignores.delete(bn)
1318
end
14-
1519
rm_rf tapd
20+
21+
tf = Tempfile.new("brew-untap")
22+
tf.write(gitignores.join("\n"))
23+
tf.close
24+
mv tf.path, "#{HOMEBREW_PREFIX}/Library/Formula/.gitignore"
1625
end
1726
end

0 commit comments

Comments
 (0)