Skip to content

Commit

Permalink
Log error output when a git command fails
Browse files Browse the repository at this point in the history
  • Loading branch information
orien committed Jan 14, 2025
1 parent 81eea0f commit 98a8a40
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/models/git_repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

require 'tempfile'

# Responsible for all git knowledge of a repo
# Caches a local mirror (not a full checkout) and creates a workspace when deploying
class GitRepository
Expand Down Expand Up @@ -184,13 +187,16 @@ def instance_cache(key)
# success: stdout as string
# error: nil
def capture_stdout(*command, dir: repo_cache_dir)
success, output = Samson::CommandExecutor.execute(
*command,
whitelist_env: ['HOME', 'PATH'],
timeout: 30.minutes,
err: '/dev/null',
dir: dir
)
output.strip if success
Tempfile.create('git-stderr') do |error_file|
success, output = Samson::CommandExecutor.execute(
*command,
whitelist_env: ['HOME', 'PATH'],
timeout: 30.minutes,
err: error_file.path,
dir: dir
)
Rails.logger.error("Failed to run command #{command}: #{error_file.read}") unless success
output.strip if success
end
end
end

0 comments on commit 98a8a40

Please sign in to comment.