File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments