Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Unreleased

* (patch) Fix 5-second timeout when unshallowing git repo (https://github.com/KnapsackPro/knapsack_pro-ruby/pull/328)

### 9.2.2

* RSpec: Skip unneeded API call when queue is already initialized in `rake knapsack_pro:queue:rspec:initialize` and improve error handling (https://github.com/KnapsackPro/knapsack_pro-ruby/pull/326).
Expand Down
41 changes: 31 additions & 10 deletions lib/knapsack_pro/repository_adapters/git_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,39 @@ def build_author
private

def git_commit_authors
if KnapsackPro::Config::Env.ci? && shallow_repository?
command = 'git fetch --shallow-since "one month ago" --quiet 2>/dev/null'
begin
Timeout.timeout(5) do
`#{command}`
end
rescue Timeout::Error
KnapsackPro.logger.debug("Skip the `#{command}` command because it took too long.")
end
git_unshallow if KnapsackPro::Config::Env.ci? && shallow_repository?
`git log --since "one month ago" 2>/dev/null | git shortlog --summary --email 2>/dev/null`
end

def git_unshallow
args = ['git', 'fetch', '--quiet', '--shallow-since', 'one month ago']

begin
pid = Process.spawn(*args, [:out, :err] => File::NULL)
rescue StandardError => e
KnapsackPro.logger.debug("Failed to unshallow (#{args.join(' ')}): #{e.message}")
return
end

`git log --since "one month ago" 2>/dev/null | git shortlog --summary --email 2>/dev/null`
begin
Timeout.timeout(5) { safe_waitpid(pid) }
rescue Timeout::Error
safe_kill(pid)
Timeout.timeout(1) { safe_waitpid(pid) } rescue Timeout::Error
KnapsackPro.logger.debug("Failed to unshallow (#{args.join(' ')}) in 5 seconds")
end
end

def safe_waitpid(pid)
Process.waitpid(pid)
rescue Errno::ECHILD
nil
end

def safe_kill(pid)
Process.kill('KILL', pid)
rescue Errno::ESRCH
nil
end

def git_build_author
Expand Down