-
Notifications
You must be signed in to change notification settings - Fork 0
/
svn-ignore
executable file
·88 lines (61 loc) · 1.35 KB
/
svn-ignore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env ruby
require 'pp'
require 'tempfile'
HELP=<<__
usage: svn-ignore [+-] [-h|--help] path...
+ (add) is the default.
paths can be specified on the command line, or on stdin
paths specified on stdin can be in the form output by "svn stat":
? a/path/that/is/unknown
__
add = true
case (arg0 = ARGV.shift)
when "-h", "--help"
puts HELP
exit 1
when "+"
add = true
when "-"
add = false
when nil
else
ARGV.unshift arg0
end
args = ARGV
if args.empty? and not $stdin.tty?
args = $stdin.to_a.map do |path|
path.chomp!
# The first 6 or 7 (depending on svn version) columns all have defined possible values...
# see "svn help stat"
if path =~ /^([ ACDIMRX?!~])[ CM] +(.*)/
if $1 == '?'
path = $2
else
path = nil
end
end
path
end
end
args.compact!
if args.empty?
puts HELP
exit 1
end
#puts "add? #{add.inspect}: #{ARGV.join ', '}"
args.each do |path|
#puts "#{add ? '+' : '-'} #{path}"
dir = File.dirname(path)
file = File.basename(path)
props = `svn --non-interactive propget svn:ignore '#{dir}'`
unless $?.success?
exit 1
end
props = props.split
props.send(add ? :<< : :delete, file)
props = props.sort.uniq
t = Tempfile.new("_svn_ignore_")
t.write(props.join("\n"))
t.flush
system("svn --non-interactive propset --file #{t.path} svn:ignore '#{dir}'")
end