Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit 26b3832

Browse files
authored
Merge pull request #4124 from envato/error-output
Log error output when a git command fails
2 parents 81eea0f + 0778ded commit 26b3832

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

app/models/git_repository.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# frozen_string_literal: true
2+
3+
require 'tempfile'
4+
25
# Responsible for all git knowledge of a repo
36
# Caches a local mirror (not a full checkout) and creates a workspace when deploying
47
class GitRepository
@@ -184,13 +187,16 @@ def instance_cache(key)
184187
# success: stdout as string
185188
# error: nil
186189
def capture_stdout(*command, dir: repo_cache_dir)
187-
success, output = Samson::CommandExecutor.execute(
188-
*command,
189-
whitelist_env: ['HOME', 'PATH'],
190-
timeout: 30.minutes,
191-
err: '/dev/null',
192-
dir: dir
193-
)
194-
output.strip if success
190+
Tempfile.create('git-stderr') do |error_file|
191+
success, output = Samson::CommandExecutor.execute(
192+
*command,
193+
whitelist_env: ['HOME', 'PATH'],
194+
timeout: 30.minutes,
195+
err: error_file.path,
196+
dir: dir
197+
)
198+
Rails.logger.error("Failed to run command #{command}: #{error_file.read}") unless success
199+
output.strip if success
200+
end
195201
end
196202
end

test/models/git_repository_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def call
101101
repository.commit_from_ref('NOT A VALID REF').must_be_nil
102102
end
103103

104+
it 'logs an error if ref does not exist' do
105+
create_repo_with_tags
106+
Rails.logger.expects(:error).with { |message| message.must_match(/^Failed to run command/) }
107+
repository.commit_from_ref('NOT A VALID REF')
108+
end
109+
104110
it 'returns the commit of a branch' do
105111
create_repo_with_an_additional_branch('my_branch')
106112
repository.commit_from_ref('my_branch').must_match /^[0-9a-f]{40}$/

0 commit comments

Comments
 (0)