Commit 9a26e9a0d634c8bb796f0b08f6397d1e343bd4be

Authored by Dmitriy Zaporozhets
1 parent 541d8994

Dont init repo on every create(:repo)

app/helpers/commits_helper.rb
@@ -147,10 +147,6 @@ module CommitsHelper @@ -147,10 +147,6 @@ module CommitsHelper
147 147
148 protected 148 protected
149 149
150 - def no_commit_message  
151 - "--no commit message"  
152 - end  
153 -  
154 # Private: Returns a link to a person. If the person has a matching user and 150 # Private: Returns a link to a person. If the person has a matching user and
155 # is a member of the current @project it will link to the team member page. 151 # is a member of the current @project it will link to the team member page.
156 # Otherwise it will link to the person email as specified in the commit. 152 # Otherwise it will link to the person email as specified in the commit.
app/models/gollum_wiki.rb
@@ -90,13 +90,17 @@ class GollumWiki @@ -90,13 +90,17 @@ class GollumWiki
90 private 90 private
91 91
92 def create_repo! 92 def create_repo!
93 - if gitlab_shell.add_repository(path_with_namespace) 93 + if init_repo(path_with_namespace)
94 Gollum::Wiki.new(path_to_repo) 94 Gollum::Wiki.new(path_to_repo)
95 else 95 else
96 raise CouldNotCreateWikiError 96 raise CouldNotCreateWikiError
97 end 97 end
98 end 98 end
99 99
  100 + def init_repo(path_with_namespace)
  101 + gitlab_shell.add_repository(path_with_namespace)
  102 + end
  103 +
100 def commit_details(action, message = nil, title = nil) 104 def commit_details(action, message = nil, title = nil)
101 commit_message = message || default_message(action, title) 105 commit_message = message || default_message(action, title)
102 106
lib/gitlab/git/commit.rb
@@ -144,6 +144,10 @@ module Gitlab @@ -144,6 +144,10 @@ module Gitlab
144 rescue 144 rescue
145 true 145 true
146 end 146 end
  147 +
  148 + def no_commit_message
  149 + "--no commit message"
  150 + end
147 end 151 end
148 end 152 end
149 end 153 end
spec/factories.rb
@@ -86,9 +86,9 @@ FactoryGirl.define do @@ -86,9 +86,9 @@ FactoryGirl.define do
86 target_branch "master" # pretend bcf03b5d~3 86 target_branch "master" # pretend bcf03b5d~3
87 source_branch "stable" # pretend bcf03b5d 87 source_branch "stable" # pretend bcf03b5d
88 st_commits do 88 st_commits do
89 - [Commit.new(project.repo.commit('bcf03b5d')),  
90 - Commit.new(project.repo.commit('bcf03b5d~1')),  
91 - Commit.new(project.repo.commit('bcf03b5d~2'))] 89 + [Commit.new(project.repository.commit('bcf03b5d')),
  90 + Commit.new(project.repository.commit('bcf03b5d~1')),
  91 + Commit.new(project.repository.commit('bcf03b5d~2'))]
92 end 92 end
93 st_diffs do 93 st_diffs do
94 project.repo.diff("bcf03b5d~3", "bcf03b5d") 94 project.repo.diff("bcf03b5d~3", "bcf03b5d")
@@ -120,6 +120,7 @@ FactoryGirl.define do @@ -120,6 +120,7 @@ FactoryGirl.define do
120 factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff] 120 factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
121 121
122 trait :on_commit do 122 trait :on_commit do
  123 + project factory: :project_with_code
123 commit_id "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" 124 commit_id "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
124 noteable_type "Commit" 125 noteable_type "Commit"
125 end 126 end
@@ -129,6 +130,7 @@ FactoryGirl.define do @@ -129,6 +130,7 @@ FactoryGirl.define do
129 end 130 end
130 131
131 trait :on_merge_request do 132 trait :on_merge_request do
  133 + project factory: :project_with_code
132 noteable_id 1 134 noteable_id 1
133 noteable_type "MergeRequest" 135 noteable_type "MergeRequest"
134 end 136 end
spec/models/commit_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 describe Commit do 3 describe Commit do
4 - let(:commit) { create(:project).repository.commit } 4 + let(:commit) { create(:project_with_code).repository.commit }
5 5
6 6
7 describe '#title' do 7 describe '#title' do
spec/models/gollum_wiki_spec.rb
@@ -81,7 +81,7 @@ describe GollumWiki do @@ -81,7 +81,7 @@ describe GollumWiki do
81 end 81 end
82 82
83 it "raises CouldNotCreateWikiError if it can't create the wiki repository" do 83 it "raises CouldNotCreateWikiError if it can't create the wiki repository" do
84 - Gitlab::Shell.any_instance.stub(:add_repository).and_return(false) 84 + GollumWiki.any_instance.stub(:init_repo).and_return(false)
85 expect { GollumWiki.new(project, user).wiki }.to raise_exception(GollumWiki::CouldNotCreateWikiError) 85 expect { GollumWiki.new(project, user).wiki }.to raise_exception(GollumWiki::CouldNotCreateWikiError)
86 end 86 end
87 end 87 end
spec/support/test_env.rb
@@ -17,11 +17,12 @@ module TestEnv @@ -17,11 +17,12 @@ module TestEnv
17 repos_path = Rails.root.join('tmp', 'test-git-base-path') 17 repos_path = Rails.root.join('tmp', 'test-git-base-path')
18 Gitlab.config.gitlab_shell.stub(repos_path: repos_path) 18 Gitlab.config.gitlab_shell.stub(repos_path: repos_path)
19 19
20 - Gitlab::Shell.any_instance.stub(:add_repository) do |path| 20 + GollumWiki.any_instance.stub(:init_repo) do |path|
21 create_temp_repo(File.join(repos_path, "#{path}.git")) 21 create_temp_repo(File.join(repos_path, "#{path}.git"))
22 end 22 end
23 23
24 Gitlab::Shell.any_instance.stub( 24 Gitlab::Shell.any_instance.stub(
  25 + add_repository: true,
25 mv_repository: true, 26 mv_repository: true,
26 remove_repository: true, 27 remove_repository: true,
27 add_key: true, 28 add_key: true,