Detect local changes before a git update. See issue #75.
This commit is contained in:
@@ -34,6 +34,14 @@ class GitUpdater < Updater
|
|||||||
%x[git #{repo_directory_arguments()} pull]
|
%x[git #{repo_directory_arguments()} pull]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_local_changes?
|
||||||
|
%x[git diff --exit-code 2>&1] =~ /diff/ ? true : false
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_head
|
||||||
|
%x[git #{repo_directory_arguments()} reset --hard HEAD]
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def repo_directory_arguments
|
def repo_directory_arguments
|
||||||
if @repo_directory
|
if @repo_directory
|
||||||
|
|||||||
@@ -44,4 +44,22 @@ describe GitUpdater do
|
|||||||
@git_updater.update().should === "Already up-to-date."
|
@git_updater.update().should === "Already up-to-date."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#has_local_changes?" do
|
||||||
|
after :each do
|
||||||
|
stub_system_command(@git_updater, /^git diff --exit-code 2>&1/, @stub_value)
|
||||||
|
@git_updater.has_local_changes?.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true if there are local changes" do
|
||||||
|
@stub_value = 'diff'
|
||||||
|
@expected = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return false if there are no local changes" do
|
||||||
|
@stub_value = ''
|
||||||
|
@expected = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ begin
|
|||||||
# Check for updates
|
# Check for updates
|
||||||
if wpscan_options.update
|
if wpscan_options.update
|
||||||
unless @updater.nil?
|
unless @updater.nil?
|
||||||
|
if @updater.has_local_changes?
|
||||||
|
puts "#{red('[!]')} Local file changes detected, an update will override local changes, do you want to continue updating? [y/n]"
|
||||||
|
Readline.readline =~ /^y/i ? @updater.reset_head : raise('Update aborted')
|
||||||
|
end
|
||||||
puts @updater.update()
|
puts @updater.update()
|
||||||
else
|
else
|
||||||
puts "Svn / Git not installed, or wpscan has not been installed with one of them."
|
puts "Svn / Git not installed, or wpscan has not been installed with one of them."
|
||||||
|
|||||||
Reference in New Issue
Block a user