-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-walk
executable file
·80 lines (60 loc) · 1.24 KB
/
git-walk
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
#!/usr/bin/ruby -w
require "find"
require "optparse"
require "ostruct"
Options = OpenStruct.new
Options.verbose = 1
OptionParser.new do |opts|
opts.banner = "Usage: git-walk [options] [<command>]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
if v
Options.verbose += 1
else
Options.verbose = 0
end
end
opts.on("-q", "--[no-]quiet", "Run quiet") do |q|
if q
Options.verbose = 0
else
Options.verbose = 1
end
end
opts.on("-w", "--walk PATH", "Path to start walking from.") do |v|
Options.walk ||= []
Options.walk << v
end
end.parse!
Cmd = ARGV
unless Options.walk
Options.walk = [ "." ]
end
if Options.verbose > 1
p Options
p Cmd
end
Find.find(*Options.walk) do |path|
puts "? "+path if Options.verbose > 1
next unless FileTest.directory? path
next unless FileTest.directory? path+"/.git"
begin
pwd = Dir.pwd
Dir.chdir path
if Cmd.empty?
puts path
next
end
cmd = Cmd.dup
if Options.verbose > 0
puts "cd #{path}; #{cmd.join " "}"
end
system(*cmd)
unless $?.success?
$stderr.write "cmd failed with #{$?} - #{cmd.inspect}"
exit 1
end
ensure
Dir.chdir pwd
Find.prune
end
end