Skip to content

Commit 727ae1a

Browse files
committed
Revise git read strategy for app file
1 parent 8cd38f3 commit 727ae1a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/models/examples/app_file.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def readlines
3939
end
4040

4141
def read
42-
return git_read if @revision == "HEAD" # Don’t cache HEAD
42+
return disk_read if @revision == "HEAD" # Don’t cache HEAD
4343

4444
Rails.cache.fetch([:app_file, @revision, @path]) { git_read }
4545
end
@@ -78,10 +78,17 @@ def source(lines: nil)
7878

7979
private
8080

81+
def disk_read
82+
git_read.presence || file_read
83+
end
84+
85+
def file_read
86+
File.read(@path)
87+
end
88+
8189
def git_read
82-
Dir.chdir(ENV.fetch("REPOSITORY_ROOT", ".")) do
83-
`git show #{@revision}:#{@path}`
84-
end
90+
git_dir = ENV.fetch("REPOSITORY_ROOT", ".")
91+
`(cd #{git_dir} && git show #{@revision}:#{@path}) 2>/dev/null`
8592
end
8693
end
8794
end

0 commit comments

Comments
 (0)