X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ae931becad1e90bcecd47c6d51dc04eee632d1f5..cec8e2705d260c9df1042858941419a3b9160c0e:/services/api/app/models/commit.rb diff --git a/services/api/app/models/commit.rb b/services/api/app/models/commit.rb index 32125a2fc2..921c690cd0 100644 --- a/services/api/app/models/commit.rb +++ b/services/api/app/models/commit.rb @@ -2,10 +2,12 @@ # # SPDX-License-Identifier: AGPL-3.0 +require 'request_error' + class Commit < ActiveRecord::Base extend CurrentApiClient - class GitError < StandardError + class GitError < RequestError def http_status 422 end @@ -149,7 +151,7 @@ class Commit < ActiveRecord::Base dst_gitdir = Rails.configuration.git_internal_dir begin - commit_in_dst = must_git(dst_gitdir, "rev-parse --verify #{sha1.shellescape}^{commit}").strip + commit_in_dst = must_git(dst_gitdir, "log -n1 --format=%H #{sha1.shellescape}^{commit}").strip rescue GitError commit_in_dst = false end @@ -173,6 +175,11 @@ class Commit < ActiveRecord::Base branch = m[1] must_git(dst_gitdir, "fetch file://#{src_gitdir.shellescape} #{branch.shellescape}") + # Even if all of the above steps succeeded, we might still not + # have the right commit due to a race, in which case tag_cmd + # will fail, and we'll need to fall back to pack|unpack. So + # don't be tempted to condense this tag_cmd and the one in the + # rescue block into a single attempt. must_git(dst_gitdir, tag_cmd) rescue GitError must_pipe("echo #{sha1.shellescape}", @@ -214,7 +221,7 @@ class Commit < ActiveRecord::Base end def self.cache_dir_base - Rails.root.join 'tmp', 'git' + Rails.root.join 'tmp', 'git-cache' end def self.fetch_remote_repository gitdir, git_url