summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-12-07 22:37:43 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-12-07 22:37:43 +0800
commit5ecd0c81af85476c2328d3836cc68b17ebd5a8a6 (patch)
treeca4896ab211f3de60f9ca9a8a19b8db288b5146f /app/models
parent6ae1a73cfdad4b98176bb99846042d4378119de2 (diff)
downloadgitlab-ce-5ecd0c81af85476c2328d3836cc68b17ebd5a8a6.tar.gz
Commit outside the hooks if possible:
So we still commit outside the hooks, and only update ref inside the hooks. There are only two exceptions: * Whenever it's adding a tag. We can't add a tag without committing, unfortunately. See !7700 * Whenever source project is in another repository. We'll need to fetch ref otherwise commits can't be made. See the whole discussion starting from: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_19210942
Diffstat (limited to 'app/models')
-rw-r--r--app/models/repository.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 36cbb0d051e..9393d6b461e 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -973,7 +973,8 @@ class Repository
base_branch,
source_branch: source_branch, source_project: source_project) do
- source_sha = find_branch(base_branch).dereferenced_target.sha
+ source_sha = source_project.repository.find_source_sha(
+ source_branch || base_branch)
committer = user_to_committer(user)
Rugged::Commit.create(rugged,
@@ -996,7 +997,8 @@ class Repository
base_branch,
source_branch: source_branch, source_project: source_project) do
- source_sha = find_branch(base_branch).dereferenced_target.sha
+ source_sha = source_project.repository.find_source_sha(
+ source_branch || base_branch)
committer = user_to_committer(user)
Rugged::Commit.create(rugged,
@@ -1162,6 +1164,16 @@ class Repository
end
end
+ protected
+
+ def find_source_sha(branch_name)
+ if branch_exists?(branch_name)
+ find_branch(branch_name).dereferenced_target.sha
+ else
+ Gitlab::Git::BLANK_SHA
+ end
+ end
+
private
def refs_directory_exists?