Skip to content

Commit b4f043c

Browse files
pftgclaude
andcommitted
fix: VCS checkout_vcs path resolution for CI
expand_path before Dir.chdir, git rev-parse inside chdir, early return when not in git repo. Fixes mixed absolute/relative path errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d63498a commit b4f043c

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/capybara/screenshot/diff/vcs.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ module Vcs
99
SILENCE_ERRORS = Os::ON_WINDOWS ? "2>nul" : "2>/dev/null"
1010

1111
def self.checkout_vcs(root, screenshot_path, checkout_path)
12-
vcs_file_path = screenshot_path.relative_path_from(root)
12+
abs_screenshot_path = Pathname.new(screenshot_path).expand_path
1313
redirect_target = "#{checkout_path} #{SILENCE_ERRORS}"
14-
show_command = "git show HEAD~0:./#{vcs_file_path}"
1514

1615
Dir.chdir(root) do
16+
git_toplevel = `git rev-parse --show-toplevel 2>/dev/null`.chomp
17+
return false if git_toplevel.empty?
18+
19+
vcs_file_path = abs_screenshot_path.relative_path_from(Pathname.new(git_toplevel))
20+
show_command = "git show HEAD:#{vcs_file_path}"
1721
if Screenshot.use_lfs
1822
system("#{show_command} > #{checkout_path}.tmp #{SILENCE_ERRORS}", exception: !!ENV["DEBUG"])
1923

test/unit/vcs_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class VcsTest < ActiveSupport::TestCase
99
include Vcs
1010

1111
setup do
12+
FileUtils.mkdir_p(Screenshot.root)
1213
@base_screenshot = Tempfile.new(%w[vcs_base_screenshot. .attempt.0.png], Screenshot.root)
1314
end
1415

0 commit comments

Comments
 (0)