@@ -40,6 +40,15 @@ def is_svn
40
40
File . directory? ( File . join ( @msfbase_dir , ".svn" ) )
41
41
end
42
42
43
+ # Adding an upstream enables msfupdate to pull updates from
44
+ # Rapid7's metasploit-framework repo instead of the repo
45
+ # the user originally cloned or forked.
46
+ def add_git_upstream
47
+ $stdout. puts "[*] Attempting to add remote 'upstream' to your local git repository."
48
+ system ( "git" , "remote" , "add" , "upstream" , "git://github.com/rapid7/rapid7metasploit-framework.git" )
49
+ $stdout. puts "[*] Added remote 'upstream' to your local git repository."
50
+ end
51
+
43
52
def print_deprecation_warning
44
53
$stdout. puts "[*] Deprecation Note: The next version of Metasploit will"
45
54
$stdout. puts "[*] update over the git protocol, which requires outbound"
102
111
103
112
####### Since we're Git, do it all that way #######
104
113
if is_git
105
- remote = @git_remote || "origin"
106
- branch = @git_branch || "master"
114
+ out = `git remote show upstream`
115
+ add_git_upstream unless $?. success? and out =~ %r{(https|git|git@github\. com):(//github\. com/)?(rapid7/metasploit-framework\. git)}
116
+
117
+ remote = @git_remote || "upstream"
118
+ branch = @git_branchch || "master"
119
+
107
120
# This will save local changes in a stash, but won't
108
121
# attempt to reapply them. If the user wants them back
109
122
# they can always git stash pop them, and that presumes
@@ -114,22 +127,23 @@ if is_git
114
127
# Note, this requires at least user.name and user.email
115
128
# to be configured in the global git config. Installers should
116
129
# take care that this is done. TODO: Enforce this in msfupdate
117
- res = system ( "git" , "stash " )
118
- if res . nil?
130
+ committed = system ( "git" , "diff" , "--quiet" , "HEAD ")
131
+ if committed . nil?
119
132
$stderr. puts "[-] ERROR: Failed to run git"
120
133
$stderr. puts ""
121
134
$stderr. puts "[-] If you used a binary installer, make sure you run the symlink in"
122
135
$stderr. puts "[-] /usr/local/bin instead of running this file directly (e.g.: ./msfupdate)"
123
136
$stderr. puts "[-] to ensure a proper environment."
124
137
exit 1
125
- else
126
- $stdout. puts "[*] Stashed local changes (if any) to avoid merge conflicts."
127
- $stdout. puts "[*] Run 'git stash pop' to reapply local changes."
138
+ elsif not committed
139
+ system ( "git" , "stash" )
140
+ $stdout. puts "[*] Stashed local changes to avoid merge conflicts."
141
+ $stdout. puts "[*] Run `git stash pop` to reapply local changes."
128
142
end
129
143
130
144
system ( "git" , "reset" , "HEAD" , "--hard" )
131
145
system ( "git" , "checkout" , branch )
132
- system ( "git" , "fetch" )
146
+ system ( "git" , "fetch" , remote )
133
147
system ( "git" , "merge" , "#{ remote } /#{ branch } " )
134
148
end
135
149
0 commit comments