lib/capybara/screenshot/diff/vcs.rb in capybara-screenshot-diff-1.9.0 vs lib/capybara/screenshot/diff/vcs.rb in capybara-screenshot-diff-1.9.2
- old
+ new
@@ -4,43 +4,49 @@
module Capybara
module Screenshot
module Diff
module Vcs
- SILENCE_ERRORS = Os::ON_WINDOWS ? "2>nul" : "2>/dev/null"
+ def self.checkout_vcs(root, screenshot_path, checkout_path)
+ if svn?(root)
+ restore_svn_revision(screenshot_path, checkout_path)
+ else
+ restore_git_revision(screenshot_path, checkout_path, root: root)
+ end
+ end
- def self.restore_git_revision(screenshot_path, checkout_path)
- vcs_file_path = screenshot_path.relative_path_from(Screenshot.root)
+ def self.svn?(root)
+ (root / ".svn").exist?
+ end
+ SILENCE_ERRORS = Os::ON_WINDOWS ? "2>nul" : "2>/dev/null"
+
+ def self.restore_git_revision(screenshot_path, checkout_path = screenshot_path, root:)
+ vcs_file_path = screenshot_path.relative_path_from(root)
redirect_target = "#{checkout_path} #{SILENCE_ERRORS}"
show_command = "git show HEAD~0:./#{vcs_file_path}"
- if Screenshot.use_lfs
- `#{show_command} > #{checkout_path}.tmp #{SILENCE_ERRORS}`
- if $CHILD_STATUS == 0
- `git lfs smudge < #{checkout_path}.tmp > #{redirect_target}`
+
+ Dir.chdir(root) do
+ if Screenshot.use_lfs
+ system("#{show_command} > #{checkout_path}.tmp #{SILENCE_ERRORS}", exception: !!ENV["DEBUG"])
+
+ `git lfs smudge < #{checkout_path}.tmp > #{redirect_target}` if $CHILD_STATUS == 0
+
+ File.delete "#{checkout_path}.tmp"
+ else
+ system("#{show_command} > #{redirect_target}", exception: !!ENV["DEBUG"])
end
- File.delete "#{checkout_path}.tmp"
- else
- `#{show_command} > #{redirect_target}`
end
if $CHILD_STATUS != 0
checkout_path.delete if checkout_path.exist?
false
else
true
end
end
- def self.checkout_vcs(screenshot_path, checkout_path)
- if svn?
- restore_svn_revision(screenshot_path, checkout_path)
- else
- restore_git_revision(screenshot_path, checkout_path)
- end
- end
-
def self.restore_svn_revision(screenshot_path, checkout_path)
committed_file_name = screenshot_path + "../.svn/text-base/" + "#{screenshot_path.basename}.svn-base"
if committed_file_name.exist?
FileUtils.cp(committed_file_name, checkout_path)
return true
@@ -57,13 +63,9 @@
return true
end
end
false
- end
-
- def self.svn?
- (Screenshot.screenshot_area_abs / ".svn").exist?
end
end
end
end
end