summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-12-08 17:57:52 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-12-08 17:57:52 +0800
commit8384d0d8d528ffdd60c9ba9e3c0c9f688cb560ef (patch)
treefb84cc230333c82d64b248f4fa83a0d5b8d49c24 /app/models
parent23032467d4a1282f69e76bba921bd71c0083f7a8 (diff)
downloadgitlab-ce-8384d0d8d528ffdd60c9ba9e3c0c9f688cb560ef.tar.gz
Introduce Repository#with_tmp_ref which we need
commits from the other repository. We'll cleanup the tmp ref after we're done with our business.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/merge_request_diff.rb3
-rw-r--r--app/models/repository.rb15
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb
index b8f36a2c958..7946d8e123e 100644
--- a/app/models/merge_request_diff.rb
+++ b/app/models/merge_request_diff.rb
@@ -169,7 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base
# When compare merge request versions we want diff A..B instead of A...B
# so we handle cases when user does squash and rebase of the commits between versions.
# For this reason we set straight to true by default.
- CompareService.new.execute(project, head_commit_sha, project, sha, straight: straight)
+ CompareService.new(project, head_commit_sha).
+ execute(project, sha, straight: straight)
end
def commits_count
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 73a9e269a65..ced68b9d274 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -1099,6 +1099,21 @@ class Repository
Gitlab::Popen.popen(args, path_to_repo).first.lines.map(&:strip)
end
+ def with_tmp_ref(source_repository, source_branch_name)
+ random_string = SecureRandom.hex
+
+ fetch_ref(
+ source_repository.path_to_repo,
+ "#{Gitlab::Git::BRANCH_REF_PREFIX}#{source_branch_name}",
+ "refs/tmp/#{random_string}/head"
+ )
+
+ yield
+
+ ensure
+ FileUtils.rm_rf("#{path_to_repo}/refs/tmp/#{random_string}")
+ end
+
def fetch_ref(source_path, source_ref, target_ref)
args = %W(#{Gitlab.config.git.bin_path} fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref})
Gitlab::Popen.popen(args, path_to_repo)