CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/dev/add_pr_fetch.rb
Views: 1904
1
#!/usr/bin/env ruby
2
3
toplevel = %x{git rev-parse --show-toplevel}.strip
4
infile = "#{toplevel}/.git/config"
5
outfile = infile
6
$stderr.puts "Rewriting #{infile}"
7
data = File.open(infile, 'rb') {|f| f.read f.stat.size}
8
newdata = ""
9
data.each_line do |line|
10
newdata << line
11
case line
12
when /^(\s*)fetch\s*=.*remotes\/([^\/]+)\//
13
ws = $1
14
remote = $2
15
pr_line = "fetch = +refs/pull/*/head:refs/remotes/#{remote}/pr/*"
16
next if line.strip == pr_line.strip
17
if data.include? pr_line
18
$stderr.puts "Skipping #{remote}, already present"
19
next
20
else
21
@new_pr_line ||= true
22
$stderr.puts "Adding pull request fetch for #{remote}"
23
newdata << "#{ws}#{pr_line}\n"
24
end
25
end
26
end
27
28
if @new_pr_line
29
File.open(outfile, 'wb') {|f| f.write newdata}
30
$stderr.puts "Wrote #{outfile}"
31
else
32
$stderr.puts "No changes to #{outfile}"
33
end
34
35