Skip to content

Commit c14f93e

Browse files
pftgclaude
andcommitted
fix: VCS checkout_vcs fails on CI (git show path resolution)
git show HEAD~0:./relative_path fails when CWD is not the git root. Use git rev-parse --show-toplevel to get the actual repo root, then compute the relative path from there. Removes the ./ prefix that caused git to resolve paths relative to CWD instead of repo root. Also ensure tmp/ directory exists before creating Tempfile in test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 86e0468 commit c14f93e

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/capybara/screenshot/diff/vcs.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ 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+
git_root = Pathname.new(`git rev-parse --show-toplevel 2>/dev/null`.chomp)
13+
vcs_file_path = Pathname.new(screenshot_path).expand_path.relative_path_from(git_root)
1314
redirect_target = "#{checkout_path} #{SILENCE_ERRORS}"
14-
show_command = "git show HEAD~0:./#{vcs_file_path}"
15+
show_command = "git show HEAD:#{vcs_file_path}"
1516

1617
Dir.chdir(root) do
1718
if Screenshot.use_lfs

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)