-
Notifications
You must be signed in to change notification settings - Fork 7
/
msf-gitprep.rb
executable file
·71 lines (55 loc) · 1.41 KB
/
msf-gitprep.rb
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
#!/usr/bin/ruby
# The goal here is to set sensible aliases and fetch patterns for things
# that Metasploit developers like to do.
# Local:
=begin
[alias]
pr-url =!"xdg-open https://github.com/todb-r7/metasploit-model/pull/new/$1:$2...$(git branch-current) #"
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = github-r7:todb-r7/metasploit-model
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
[remote "upstream"]
url = github-r7:rapid7/metasploit-model
fetch = +refs/heads/*:refs/remotes/upstream/*
fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
[branch "upstream-master"]
remote = upstream
merge = refs/heads/master
=end
class GitInfo
attr_reader :origin_url, :repo, :uri_handler
def initialize
set_origin_url
set_repo
set_uri_handler
end
def remote_v
@remote_v ||= %x{git remote -v}
end
def set_origin_url
remote_v =~ /^origin(.*)\(push\)$/
@origin_url = $1.strip
end
def set_repo
@repo = @origin_url.split("/").last
end
def set_uri_handler
if @origin_url.start_with? "https://"
@uri_handler = "https://github.com/"
else
@uri = @origin_url.split(":").first
@uri << ":"
end
end
def add_upstream
return if @remote_v =~ /upstream\s.*rapid7\/#{@repo}/
puts "Adding upstream repo."
%x{git remote add upstream #{@uri}rapid7/#{@repo}}
end
end
def go
g = GitInfo.new
g.add_upstream
end
go