summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.travis.yml2
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock13
-rw-r--r--app/assets/stylesheets/gitlab_bootstrap/blocks.scss113
-rw-r--r--app/assets/stylesheets/gitlab_bootstrap/lists.scss12
-rw-r--r--app/assets/stylesheets/gitlab_bootstrap/tables.scss2
-rw-r--r--app/assets/stylesheets/sections/commits.scss82
-rw-r--r--app/assets/stylesheets/sections/issues.scss42
-rw-r--r--app/assets/stylesheets/sections/merge_requests.scss30
-rw-r--r--app/assets/stylesheets/sections/projects.scss12
-rw-r--r--app/contexts/commit_load_context.rb2
-rw-r--r--app/contexts/notes/load_context.rb4
-rw-r--r--app/contexts/test_hook_context.rb2
-rw-r--r--app/controllers/admin/projects_controller.rb5
-rw-r--r--app/controllers/admin/users_controller.rb4
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--app/controllers/commits_controller.rb4
-rw-r--r--app/controllers/merge_requests_controller.rb4
-rw-r--r--app/controllers/project_resource_controller.rb1
-rw-r--r--app/controllers/projects_controller.rb3
-rw-r--r--app/controllers/refs_controller.rb8
-rw-r--r--app/controllers/repositories_controller.rb10
-rw-r--r--app/controllers/services_controller.rb2
-rw-r--r--app/controllers/team_members_controller.rb9
-rw-r--r--app/controllers/tree_controller.rb2
-rw-r--r--app/decorators/tree_decorator.rb8
-rw-r--r--app/helpers/application_helper.rb15
-rw-r--r--app/helpers/events_helper.rb14
-rw-r--r--app/helpers/merge_requests_helper.rb2
-rw-r--r--app/models/ability.rb10
-rw-r--r--app/models/commit.rb14
-rw-r--r--app/models/event.rb30
-rw-r--r--app/models/gitlab_ci_service.rb4
-rw-r--r--app/models/note.rb7
-rw-r--r--app/models/project.rb288
-rw-r--r--app/models/protected_branch.rb2
-rw-r--r--app/models/repository.rb169
-rw-r--r--app/models/team.rb118
-rw-r--r--app/models/tree.rb7
-rw-r--r--app/models/user.rb2
-rw-r--r--app/models/users_project.rb74
-rw-r--r--app/uploaders/attachment_uploader.rb42
-rw-r--r--app/views/admin/dashboard/index.html.haml8
-rw-r--r--app/views/admin/projects/_form.html.haml2
-rw-r--r--app/views/admin/projects/show.html.haml75
-rw-r--r--app/views/commit/show.html.haml12
-rw-r--r--app/views/commits/_commit_box.html.haml35
-rw-r--r--app/views/commits/_commits.html.haml2
-rw-r--r--app/views/commits/_head.html.haml6
-rw-r--r--app/views/compare/_form.html.haml2
-rw-r--r--app/views/dashboard/_groups.html.haml2
-rw-r--r--app/views/dashboard/_projects.html.haml2
-rw-r--r--app/views/dashboard/issues.html.haml3
-rw-r--r--app/views/dashboard/merge_requests.html.haml3
-rw-r--r--app/views/groups/_projects.html.haml2
-rw-r--r--app/views/groups/issues.html.haml3
-rw-r--r--app/views/groups/merge_requests.html.haml3
-rw-r--r--app/views/groups/people.html.haml2
-rw-r--r--app/views/issues/_form.html.haml29
-rw-r--r--app/views/issues/index.html.haml2
-rw-r--r--app/views/issues/show.html.haml10
-rw-r--r--app/views/layouts/project_resource.html.haml4
-rw-r--r--app/views/merge_requests/_form.html.haml72
-rw-r--r--app/views/merge_requests/show/_commits.html.haml2
-rw-r--r--app/views/merge_requests/show/_mr_box.html.haml8
-rw-r--r--app/views/milestones/show.html.haml6
-rw-r--r--app/views/notes/_note.html.haml2
-rw-r--r--app/views/projects/_form.html.haml6
-rw-r--r--app/views/protected_branches/index.html.haml2
-rw-r--r--app/views/repositories/_branch.html.haml2
-rw-r--r--app/views/repositories/_feed.html.haml2
-rw-r--r--app/views/repositories/stats.html.haml2
-rw-r--r--app/views/repositories/tags.html.haml8
-rw-r--r--app/views/team_members/_team.html.haml2
-rw-r--r--app/views/tree/_tree.html.haml10
-rw-r--r--app/views/wikis/_form.html.haml8
-rw-r--r--app/workers/post_receive.rb2
-rw-r--r--features/steps/admin/admin_groups.rb2
-rw-r--r--features/steps/dashboard/dashboard.rb4
-rw-r--r--features/steps/dashboard/dashboard_issues.rb2
-rw-r--r--features/steps/dashboard/dashboard_merge_requests.rb4
-rw-r--r--features/steps/dashboard/dashboard_search.rb6
-rw-r--r--features/steps/group/group.rb2
-rw-r--r--features/steps/project/create_project.rb4
-rw-r--r--features/steps/project/project_browse_commits.rb6
-rw-r--r--features/steps/project/project_team_management.rb6
-rw-r--r--features/steps/shared/paths.rb14
-rw-r--r--features/steps/shared/project.rb6
-rw-r--r--lib/api/notes.rb4
-rw-r--r--lib/api/projects.rb6
-rw-r--r--lib/extracts_path.rb6
-rw-r--r--lib/gitlab/backend/gitolite_config.rb8
-rw-r--r--lib/gitlab/markdown.rb2
-rw-r--r--lib/gitlab/satellite/merge_action.rb2
-rw-r--r--lib/static_model.rb2
-rw-r--r--spec/controllers/commit_controller_spec.rb4
-rw-r--r--spec/controllers/commits_controller_spec.rb2
-rw-r--r--spec/controllers/merge_requests_controller_spec.rb2
-rw-r--r--spec/controllers/tree_controller_spec.rb2
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb6
-rw-r--r--spec/lib/extracts_path_spec.rb2
-rw-r--r--spec/models/commit_spec.rb2
-rw-r--r--spec/models/gitlab_ci_service_spec.rb4
-rw-r--r--spec/models/note_spec.rb5
-rw-r--r--spec/models/project_hooks_spec.rb6
-rw-r--r--spec/models/project_repository_spec.rb159
-rw-r--r--spec/models/project_spec.rb60
-rw-r--r--spec/models/protected_branch_spec.rb2
-rw-r--r--spec/models/repository_spec.rb105
-rw-r--r--spec/models/system_hook_spec.rb4
-rw-r--r--spec/models/team_spec.rb18
-rw-r--r--spec/models/users_project_spec.rb10
-rw-r--r--spec/requests/api/issues_spec.rb2
-rw-r--r--spec/requests/api/merge_requests_spec.rb2
-rw-r--r--spec/requests/api/milestones_spec.rb2
-rw-r--r--spec/requests/api/notes_spec.rb2
-rw-r--r--spec/requests/api/projects_spec.rb6
-rw-r--r--spec/requests/atom/issues_spec.rb2
-rw-r--r--spec/requests/gitlab_flavored_markdown_spec.rb6
-rw-r--r--spec/requests/issues_spec.rb3
-rw-r--r--spec/requests/projects_deploy_keys_spec.rb2
-rw-r--r--spec/requests/projects_spec.rb8
-rw-r--r--spec/requests/search_spec.rb2
-rw-r--r--spec/requests/security/project_access_spec.rb12
-rw-r--r--spec/requests/snippets_spec.rb4
-rw-r--r--spec/support/stubbed_repository.rb21
127 files changed, 950 insertions, 1127 deletions
diff --git a/.gitignore b/.gitignore
index 94a210b9461..24297583fd2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@ db/data.yml
.DS_Store
.chef
vendor/bundle/*
+rails_best_practices_output.html
diff --git a/.travis.yml b/.travis.yml
index 59d22f32ee3..e8bd744267f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,7 +8,7 @@ branches:
only:
- 'master'
rvm:
- - 1.9.3
+ - 1.9.2
services:
- mysql
- postgresql
diff --git a/Gemfile b/Gemfile
index 4defcec325f..6a2d6a8042d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -123,6 +123,8 @@ group :development do
gem 'better_errors'
gem 'binding_of_caller'
+ gem 'rails_best_practices'
+
# Docs generator
gem "sdoc"
end
diff --git a/Gemfile.lock b/Gemfile.lock
index 4b08c3141b4..722881e5768 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -132,6 +132,8 @@ GEM
chosen-rails (0.9.8)
railties (~> 3.0)
thor (~> 0.14)
+ code_analyzer (0.3.1)
+ sexp_processor
coderay (1.0.8)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@@ -302,6 +304,7 @@ GEM
pg (0.14.1)
polyglot (0.3.3)
posix-spawn (0.3.6)
+ progressbar (0.12.0)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
@@ -335,6 +338,14 @@ GEM
rails-dev-tweaks (0.6.1)
actionpack (~> 3.1)
railties (~> 3.1)
+ rails_best_practices (1.13.2)
+ activesupport
+ awesome_print
+ code_analyzer
+ colored
+ erubis
+ i18n
+ progressbar
railties (3.2.9)
actionpack (= 3.2.9)
activesupport (= 3.2.9)
@@ -393,6 +404,7 @@ GEM
multi_json (~> 1.0)
rubyzip
settingslogic (2.0.8)
+ sexp_processor (4.1.3)
shoulda-matchers (1.3.0)
activesupport (>= 3.0.0)
simplecov (0.7.1)
@@ -512,6 +524,7 @@ DEPENDENCIES
rack-mini-profiler
rails (= 3.2.9)
rails-dev-tweaks
+ rails_best_practices
raphael-rails (= 1.5.2)
rb-fsevent
rb-inotify
diff --git a/app/assets/stylesheets/gitlab_bootstrap/blocks.scss b/app/assets/stylesheets/gitlab_bootstrap/blocks.scss
index f9c8b7b05ea..8cb1c045778 100644
--- a/app/assets/stylesheets/gitlab_bootstrap/blocks.scss
+++ b/app/assets/stylesheets/gitlab_bootstrap/blocks.scss
@@ -1,23 +1,24 @@
/**
* ===================================
- * Contain 3 main UI block elements:
- * .main_box - for show pages
- * .ui-box - for simple block & widgets
+ * Contain UI block elements:
+ * .ui-box - for any block & widgets
* ===================================
*/
/**
- * UI box element
- * contains top, middle, bottom blocks
+ * UI Block
*
*/
-.main_box {
- @extend .borders;
- @extend .prepend-top-20;
- @extend .append-bottom-20;
- border-width: 1px;
+.ui-box {
+ background: #F9F9F9;
+ margin-bottom: 25px;
+ border: 1px solid #CCC;
@include solid-shade;
+ &.ui-box-show {
+ margin:20px 0;
+ background: #FFF;
+ }
img { max-width: 100%; }
@@ -27,9 +28,9 @@
}
}
- .top_box_content,
- .middle_box_content,
- .bottom_box_content {
+ .ui-box-head,
+ .ui-box-body,
+ .ui-box-bottom {
padding: 15px;
word-wrap: break-word;
@@ -39,19 +40,25 @@
border: none;
padding: 0;
}
+
+ .clearfix {
+ margin: 0;
+ }
}
- .top_box_content {
+ .ui-box-head {
.box-title {
color: $style_color;
font-size: 18px;
font-weight: normal;
line-height: 28px;
}
+ h3 {
+ margin: 0;
+ }
}
- .middle_box_content {
- @include border-radius(0);
+ .ui-box-body {
border: none;
font-size: 12px;
background-color: #f5f5f5;
@@ -59,24 +66,9 @@
border-top: 1px solid #eee;
}
- .bottom_box_content {
+ .ui-box-bottom {
border-top: 1px solid #eee;
}
-}
-
-/**
- * Big UI Block for show page content
- *
- */
-.ui-box {
- background: #F9F9F9;
- margin-bottom: 25px;
-
- border: 1px solid #eaeaea;
- @include border-radius(4px);
-
- border-color: #CCC;
- @include solid-shade;
&.white {
background: #fff;
@@ -86,47 +78,47 @@
margin: 0;
}
- h5, .title {
- padding: 0 10px;
- @include border-radius(4px 4px 0 0);
+ .title {
@include bg-gray-gradient;
- border-top: 1px solid #eaeaea;
- border-bottom: 1px solid #bbb;
+ border-bottom: 1px solid #CCC;
+ color: #456;
+ font-size: 16px;
+ text-shadow: 0 1px 1px #fff;
+ padding: 0px 10px;
+ line-height: 36px;
+ font-size: 14px;
+ font-weight: normal;
> a {
text-shadow: 0 1px 1px #fff;
}
- &.small {
- line-height: 28px;
- font-size: 14px;
- line-height: 28px;
- text-shadow: 0 1px 1px white;
- }
-
form {
- padding: 9px 0;
- margin: 0px;
+ margin-bottom: 0;
+ margin-top: 3px;
}
.nav-pills {
- li {
- padding: 3px 0;
- &.active a { background-color: $style_color; }
- a {
- @include border-radius(7px);
+ > li {
+ > a {
+ padding: 13px;
+ margin: 0;
+ font-size: 13px;
+ }
+ &.active {
+ > a {
+ background: #D5D5D5;
+ color: $style_color;
+ @include border-radius(0);
+ border-radius: 0;
+ border-left: 1px solid #CCC;
+ border-right: 1px solid #CCC;
+ }
}
}
}
}
- .bottom {
- @include bg-gray-gradient;
- @include border-radius(0 0 4px 4px);
- border-bottom: none;
- border-top: 1px solid #bbb;
- }
-
&.padded {
h5, .title {
margin: -20px;
@@ -143,6 +135,7 @@
color: #777;
}
}
+
.row_title {
font-weight: bold;
color: #444;
@@ -151,8 +144,4 @@
text-decoration: underline;
}
}
-
- .ui-box-body {
- padding: 10px;
- }
}
diff --git a/app/assets/stylesheets/gitlab_bootstrap/lists.scss b/app/assets/stylesheets/gitlab_bootstrap/lists.scss
index edaf3cef2cf..0f893a553ee 100644
--- a/app/assets/stylesheets/gitlab_bootstrap/lists.scss
+++ b/app/assets/stylesheets/gitlab_bootstrap/lists.scss
@@ -23,14 +23,12 @@
border-bottom: 1px solid #ADF;
}
- &:first-child {
- @include border-radius(4px 4px 0 0);
- border-top: none;
- }
-
&:last-child {
- @include border-radius(0 0 4px 4px);
- border: none;
+ border-bottom: none;
+
+ &.bottom {
+ background: #f5f5f5;
+ }
}
.author { color: #999; }
diff --git a/app/assets/stylesheets/gitlab_bootstrap/tables.scss b/app/assets/stylesheets/gitlab_bootstrap/tables.scss
index 5905efd3aae..7a9eac82566 100644
--- a/app/assets/stylesheets/gitlab_bootstrap/tables.scss
+++ b/app/assets/stylesheets/gitlab_bootstrap/tables.scss
@@ -25,7 +25,7 @@ table {
}
th, td {
- padding: 8px;
+ padding: 10px;
line-height: 18px;
text-align: left;
}
diff --git a/app/assets/stylesheets/sections/commits.scss b/app/assets/stylesheets/sections/commits.scss
index 7ed53333f8c..ebec51c9715 100644
--- a/app/assets/stylesheets/sections/commits.scss
+++ b/app/assets/stylesheets/sections/commits.scss
@@ -1,74 +1,17 @@
-.commit-box {
- @extend .main_box;
-
- .commit-head {
- @extend .top_box_content;
-
- .commit-title {
- line-height: 26px;
- margin: 0;
- }
-
- .commit-description {
- font-size: 14px;
- border: none;
- background-color: white;
- padding-top: 10px;
- }
-
- .browse-button {
- @extend .btn;
- @extend .btn-small;
- float: right;
- }
- }
-
- .commit-info {
- @extend .middle_box_content;
- @extend .clearfix;
-
- .sha-block {
- text-align: right;
- &:first-child {
- padding-bottom: 6px;
- }
-
- a {
- border-bottom: 1px solid #aaa;
- margin-left: 9px;
- }
- }
-
- &.merge-commit .sha-block {
- clear: right;
- }
-
- .committer {
- padding-left: 32px;
- }
-
- .author a,
- .committer a {
- font-size: 14px;
- line-height: 22px;
- text-shadow: 0 1px 1px #fff;
- color: #777;
- &:hover {
- color: #999;
- }
- }
-
- .avatar {
- margin-right: 10px;
- }
- }
-}
-
/**
*
* COMMIT SHOw
*
*/
+.commit-committer-link,
+.commit-author-link {
+ font-size: 13px;
+ color: #555;
+ &:hover {
+ color: #999;
+ }
+}
+
.diff_file {
border: 1px solid #CCC;
margin-bottom: 1em;
@@ -255,13 +198,6 @@
min-width: 65px;
font-family: $monospace;
}
-
- .commit-author-name {
- color: #777;
- &:hover {
- color: #999;
- }
- }
}
.diff_file_header a,
diff --git a/app/assets/stylesheets/sections/issues.scss b/app/assets/stylesheets/sections/issues.scss
index fd995728978..79c592822ce 100644
--- a/app/assets/stylesheets/sections/issues.scss
+++ b/app/assets/stylesheets/sections/issues.scss
@@ -1,31 +1,3 @@
-.issue_form_box {
- @extend .main_box;
- .issue_title {
- @extend .top_box_content;
- .clearfix {
- margin-bottom: 0px;
- input {
- @extend .span8;
- }
- }
- }
- .issue_middle_block {
- @extend .middle_box_content;
- height: 30px;
- .issue_assignee {
- @extend .span6;
- float: left;
- }
- .issue_milestone {
- @extend .span4;
- float: left;
- }
- }
- .issue_description {
- @extend .bottom_box_content;
- }
-}
-
.issues_table {
.issue {
padding: 7px 10px;
@@ -89,31 +61,25 @@ input.check_all_issues {
#issues-table-holder {
.issues_filters {
- form {
- padding: 0;
- margin: 0;
- margin-top:7px
- }
}
.issues_bulk_update {
margin: 0;
form {
- padding: 0;
- margin: 0;
- margin-top:7px
+ float:left;
}
.update_selected_issues {
position: relative;
- top:-2px;
+ top:5px;
margin-left: 4px;
float: left;
}
.update_issues_text {
padding: 3px;
- line-height: 18px;
+ line-height: 28px;
float: left;
+ color: #479;
}
}
}
diff --git a/app/assets/stylesheets/sections/merge_requests.scss b/app/assets/stylesheets/sections/merge_requests.scss
index 9fb1d14967f..66ec642e057 100644
--- a/app/assets/stylesheets/sections/merge_requests.scss
+++ b/app/assets/stylesheets/sections/merge_requests.scss
@@ -1,17 +1,3 @@
-/**
- * MR form
- *
- */
-
-.mr_branch_box {
- @extend .ui-box;
- margin-bottom: 20px;
-
- .body {
- background: #f1f1f1;
- }
-
-}
/**
* MR -> show: Automerge widget
@@ -121,19 +107,3 @@ li.merge_request {
.mr_direction_tip {
margin-top:40px
}
-
-.merge_requests_form_box {
- @extend .main_box;
- .merge_requests_middle_box {
- @extend .middle_box_content;
- height: 30px;
- .merge_requests_assignee {
- @extend .span6;
- float: left;
- }
- .merge_requests_milestone {
- @extend .span4;
- float: left;
- }
- }
-}
diff --git a/app/assets/stylesheets/sections/projects.scss b/app/assets/stylesheets/sections/projects.scss
index 717f85024cc..072ade80ad3 100644
--- a/app/assets/stylesheets/sections/projects.scss
+++ b/app/assets/stylesheets/sections/projects.scss
@@ -8,16 +8,12 @@
.groups_box,
.projects_box {
- > h5 {
- color: $style_color;
- font-size: 16px;
- text-shadow: 0 1px 1px #fff;
- padding: 2px 10px;
- line-height: 32px;
- font-size: 14px;
+ > .title {
+ padding: 2px 15px;
}
.nav-projects-tabs li { padding: 0; }
.well-list {
+ li { padding: 15px; }
.arrow {
float: right;
padding: 10px;
@@ -109,7 +105,7 @@ ul.nav.nav-projects-tabs {
li {
a {
- padding: 4px 20px;
+ padding: 6px 25px;
margin-top: 2px;
border-color: #DDD;
background-color: #EEE;
diff --git a/app/contexts/commit_load_context.rb b/app/contexts/commit_load_context.rb
index e43e5a07805..a14291b9b0d 100644
--- a/app/contexts/commit_load_context.rb
+++ b/app/contexts/commit_load_context.rb
@@ -9,7 +9,7 @@ class CommitLoadContext < BaseContext
status: :ok
}
- commit = project.commit(params[:id])
+ commit = project.repository.commit(params[:id])
if commit
commit = CommitDecorator.decorate(commit)
diff --git a/app/contexts/notes/load_context.rb b/app/contexts/notes/load_context.rb
index 9f8299f52f7..907c7c7ade2 100644
--- a/app/contexts/notes/load_context.rb
+++ b/app/contexts/notes/load_context.rb
@@ -9,7 +9,7 @@ module Notes
@notes = case target_type
when "commit"
- project.commit_notes(project.commit(target_id)).fresh.limit(20)
+ project.commit_notes(project.repository.commit(target_id)).fresh.limit(20)
when "issue"
project.issues.find(target_id).notes.inc_author.fresh.limit(20)
when "merge_request"
@@ -18,7 +18,7 @@ module Notes
project.snippets.find(target_id).notes.fresh
when "wall"
# this is the only case, where the order is DESC
- project.common_notes.order("created_at DESC, id DESC").limit(50)
+ project.notes.common.inc_author_project.order("created_at DESC, id DESC").limit(50)
end
@notes = if after_id
diff --git a/app/contexts/test_hook_context.rb b/app/contexts/test_hook_context.rb
index cba5d1f87c2..d2d82a52cf5 100644
--- a/app/contexts/test_hook_context.rb
+++ b/app/contexts/test_hook_context.rb
@@ -1,7 +1,7 @@
class TestHookContext < BaseContext
def execute
hook = project.hooks.find(params[:id])
- commits = project.commits(project.default_branch, nil, 3)
+ commits = project.repository.commits(project.default_branch, nil, 3)
data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user)
hook.execute(data)
end
diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb
index e1982eee577..d5e6f3cdc0e 100644
--- a/app/controllers/admin/projects_controller.rb
+++ b/app/controllers/admin/projects_controller.rb
@@ -10,6 +10,7 @@ class Admin::ProjectsController < AdminController
end
def show
+ @repository = @project.repository
@users = User.active
@users = @users.not_in_project(@project) if @project.users.present?
@users = @users.all
@@ -19,7 +20,7 @@ class Admin::ProjectsController < AdminController
end
def team_update
- @project.add_users_ids_to_team(params[:user_ids], params[:project_access])
+ @project.team.add_users_ids(params[:user_ids], params[:project_access])
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
end
@@ -36,7 +37,7 @@ class Admin::ProjectsController < AdminController
def destroy
# Delete team first in order to prevent multiple gitolite calls
- @project.truncate_team
+ @project.team.truncate
@project.destroy
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index b255c73a21f..8669f5d1d38 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -19,9 +19,9 @@ class Admin::UsersController < AdminController
def team_update
@admin_user = User.find(params[:id])
- UsersProject.user_bulk_import(
- @admin_user,
+ UsersProject.add_users_into_projects(
params[:project_ids],
+ [@admin_user.id],
params[:project_access]
)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 75cd8f15605..3457a1ab1b4 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -76,6 +76,12 @@ class ApplicationController < ActionController::Base
end
end
+ def repository
+ @repository ||= project.repository
+ rescue Grit::NoSuchPathError
+ nil
+ end
+
def add_abilities
abilities << Ability
end
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 3b8ebdb5ddc..534ae1edd31 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -9,10 +9,10 @@ class CommitsController < ProjectResourceController
before_filter :require_non_empty_project
def show
- @repo = @project.repo
+ @repo = @project.repository
@limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
- @commits = @project.commits(@ref, @path, @limit, @offset)
+ @commits = @repo.commits(@ref, @path, @limit, @offset)
@commits = CommitDecorator.decorate(@commits)
respond_to do |format|
diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb
index fa4eaff8469..d2d92e60585 100644
--- a/app/controllers/merge_requests_controller.rb
+++ b/app/controllers/merge_requests_controller.rb
@@ -83,12 +83,12 @@ class MergeRequestsController < ProjectResourceController
end
def branch_from
- @commit = project.commit(params[:ref])
+ @commit = @repository.commit(params[:ref])
@commit = CommitDecorator.decorate(@commit)
end
def branch_to
- @commit = project.commit(params[:ref])
+ @commit = @repository.commit(params[:ref])
@commit = CommitDecorator.decorate(@commit)
end
diff --git a/app/controllers/project_resource_controller.rb b/app/controllers/project_resource_controller.rb
index 81bc3a91bd1..ea78b3ff7c4 100644
--- a/app/controllers/project_resource_controller.rb
+++ b/app/controllers/project_resource_controller.rb
@@ -1,3 +1,4 @@
class ProjectResourceController < ApplicationController
before_filter :project
+ before_filter :repository
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 47143624ec4..0df30220ebd 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -2,6 +2,7 @@ require Rails.root.join('lib', 'gitlab', 'graph', 'json_builder')
class ProjectsController < ProjectResourceController
skip_before_filter :project, only: [:new, :create]
+ skip_before_filter :repository, only: [:new, :create]
# Authorize
before_filter :authorize_read_project!, except: [:index, :new, :create]
@@ -58,7 +59,7 @@ class ProjectsController < ProjectResourceController
respond_to do |format|
format.html do
- unless @project.empty_repo?
+ if @project.repository && !@project.repository.empty?
@last_push = current_user.recent_push(@project.id)
render :show
else
diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb
index b48d5ec7027..e4eb2d33ea6 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -31,7 +31,7 @@ class RefsController < ProjectResourceController
contents = @tree.contents
@logs = contents.map do |content|
file = params[:path] ? File.join(params[:path], content.name) : content.name
- last_commit = @project.commits(@commit.id, file, 1).last
+ last_commit = @repo.commits(@commit.id, file, 1).last
last_commit = CommitDecorator.decorate(last_commit)
{
file_name: content.name,
@@ -45,10 +45,10 @@ class RefsController < ProjectResourceController
def define_tree_vars
params[:path] = nil if params[:path].blank?
- @repo = project.repo
- @commit = project.commit(@ref)
+ @repo = project.repository
+ @commit = @repo.commit(@ref)
@commit = CommitDecorator.decorate(@commit)
- @tree = Tree.new(@commit.tree, project, @ref, params[:path])
+ @tree = Tree.new(@commit.tree, @ref, params[:path])
@tree = TreeDecorator.new(@tree)
@hex_path = Digest::SHA1.hexdigest(params[:path] || "")
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 7678fbff3f1..229cb36949b 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -5,19 +5,19 @@ class RepositoriesController < ProjectResourceController
before_filter :require_non_empty_project
def show
- @activities = @project.commits_with_refs(20)
+ @activities = @repository.commits_with_refs(20)
end
def branches
- @branches = @project.branches
+ @branches = @repository.branches
end
def tags
- @tags = @project.tags
+ @tags = @repository.tags
end
def stats
- @stats = Gitlab::GitStats.new(@project.repo, @project.root_ref)
+ @stats = Gitlab::GitStats.new(@repository.raw, @repository.root_ref)
@graph = @stats.graph
end
@@ -27,7 +27,7 @@ class RepositoriesController < ProjectResourceController
end
- file_path = @project.archive_repo(params[:ref])
+ file_path = @repository.archive_repo(params[:ref])
if file_path
# Send file to user
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
index 50f7e97af9f..d0df469b967 100644
--- a/app/controllers/services_controller.rb
+++ b/app/controllers/services_controller.rb
@@ -26,7 +26,7 @@ class ServicesController < ProjectResourceController
end
def test
- commits = project.commits(project.default_branch, nil, 3)
+ commits = project.repository.commits(project.default_branch, nil, 3)
data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user)
@service = project.gitlab_ci_service
diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb
index 311af62b8db..8378a8458ff 100644
--- a/app/controllers/team_members_controller.rb
+++ b/app/controllers/team_members_controller.rb
@@ -16,10 +16,9 @@ class TeamMembersController < ProjectResourceController
end
def create
- @project.add_users_ids_to_team(
- params[:user_ids],
- params[:project_access]
- )
+ users = User.where(id: params[:user_ids])
+
+ @project.team << [users, params[:project_access]]
if params[:redirect_to]
redirect_to params[:redirect_to]
@@ -50,7 +49,7 @@ class TeamMembersController < ProjectResourceController
def apply_import
giver = Project.find(params[:source_project_id])
- status = UsersProject.import_team(giver, project)
+ status = @project.team.import(giver)
notice = status ? "Succesfully imported" : "Import failed"
redirect_to project_team_members_path(project), notice: notice
diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb
index 725f48fa014..2151bd7cbbd 100644
--- a/app/controllers/tree_controller.rb
+++ b/app/controllers/tree_controller.rb
@@ -22,7 +22,7 @@ class TreeController < ProjectResourceController
end
def edit
- @last_commit = @project.last_commit_for(@ref, @path).sha
+ @last_commit = @project.repository.last_commit_for(@ref, @path).sha
end
def update
diff --git a/app/decorators/tree_decorator.rb b/app/decorators/tree_decorator.rb
index c12227afb5d..0e760f97dee 100644
--- a/app/decorators/tree_decorator.rb
+++ b/app/decorators/tree_decorator.rb
@@ -6,16 +6,14 @@ class TreeDecorator < ApplicationDecorator
part_path = ""
parts = path.split("\/")
- #parts = parts[0...-1] if is_blob?
-
- yield(h.link_to("..", "#")) if parts.count > max_links
+ yield('..', nil) if parts.count > max_links
parts.each do |part|
part_path = File.join(part_path, part) unless part_path.empty?
part_path = part if part_path.empty?
next unless parts.last(2).include?(part) if parts.count > max_links
- yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path))))
+ yield(part, h.tree_join(ref, part_path))
end
end
end
@@ -26,7 +24,7 @@ class TreeDecorator < ApplicationDecorator
def up_dir_path
file = File.join(path, "..")
- h.project_tree_path(project, h.tree_join(ref, file))
+ h.tree_join(ref, file)
end
def readme
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2a33bae24f3..a1eea96be43 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -53,7 +53,7 @@ module ApplicationHelper
def last_commit(project)
if project.repo_exists?
- time_ago_in_words(project.commit.committed_date) + " ago"
+ time_ago_in_words(project.repository.commit.committed_date) + " ago"
else
"Never"
end
@@ -62,9 +62,11 @@ module ApplicationHelper
end
def grouped_options_refs(destination = :tree)
+ repository = @project.repository
+
options = [
- ["Branch", @project.branch_names ],
- [ "Tag", @project.tag_names ]
+ ["Branch", repository.branch_names ],
+ [ "Tag", repository.tag_names ]
]
# If reference is commit id -
@@ -100,15 +102,15 @@ module ApplicationHelper
]
project_nav = []
- if @project && !@project.new_record?
+ if @project && @project.repository && @project.repository.root_ref
project_nav = [
{ label: "#{@project.name} Issues", url: project_issues_path(@project) },
- { label: "#{@project.name} Commits", url: project_commits_path(@project, @ref || @project.root_ref) },
+ { label: "#{@project.name} Commits", url: project_commits_path(@project, @ref || @project.repository.root_ref) },
{ label: "#{@project.name} Merge Requests", url: project_merge_requests_path(@project) },
{ label: "#{@project.name} Milestones", url: project_milestones_path(@project) },
{ label: "#{@project.name} Snippets", url: project_snippets_path(@project) },
{ label: "#{@project.name} Team", url: project_team_index_path(@project) },
- { label: "#{@project.name} Tree", url: project_tree_path(@project, @ref || @project.root_ref) },
+ { label: "#{@project.name} Tree", url: project_tree_path(@project, @ref || @project.repository.root_ref) },
{ label: "#{@project.name} Wall", url: wall_project_path(@project) },
{ label: "#{@project.name} Wiki", url: project_wikis_path(@project) },
]
@@ -140,6 +142,7 @@ module ApplicationHelper
event.last_push_to_non_root? &&
!event.rm_ref? &&
event.project &&
+ event.project.repository &&
event.project.merge_requests_enabled
end
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb
index a2548a23e5e..2b9e7186bcd 100644
--- a/app/helpers/events_helper.rb
+++ b/app/helpers/events_helper.rb
@@ -20,20 +20,6 @@ module EventsHelper
[event.action_name, target].join(" ")
end
- def event_image event
- event_image_path = if event.push?
- "event_push.png"
- elsif event.merged?
- "event_mr_merged.png"
- end
-
- return nil unless event_image_path
-
- content_tag :div, class: 'event_icon' do
- image_tag event_image_path
- end
- end
-
def event_filter_link key, tooltip
key = key.to_s
diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb
index f48425bd6de..ca0a89c3749 100644
--- a/app/helpers/merge_requests_helper.rb
+++ b/app/helpers/merge_requests_helper.rb
@@ -4,7 +4,7 @@ module MergeRequestsHelper
event.project,
merge_request: {
source_branch: event.branch_name,
- target_branch: event.project.root_ref,
+ target_branch: event.project.repository.root_ref,
title: event.branch_name.titleize
}
)
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 75a7163c219..256af1e800b 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -15,17 +15,19 @@ class Ability
def project_abilities(user, project)
rules = []
+ team = project.team
+
# Rules based on role in project
- if project.master_access_for?(user)
+ if team.masters.include?(user)
rules << project_master_rules
- elsif project.dev_access_for?(user)
+ elsif team.developers.include?(user)
rules << project_dev_rules
- elsif project.report_access_for?(user)
+ elsif team.reporters.include?(user)
rules << project_report_rules
- elsif project.guest_access_for?(user)
+ elsif team.guests.include?(user)
rules << project_guest_rules
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 07c5fbd7183..7e64c0f6e82 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -11,7 +11,7 @@ class Commit
attr_accessor :commit, :head, :refs
delegate :message, :authored_date, :committed_date, :parents, :sha,
- :date, :committer, :author, :diffs, :tree, :id,
+ :date, :committer, :author, :diffs, :tree, :id, :stats,
:to_patch, to: :commit
class << self
@@ -83,8 +83,8 @@ class Commit
return result unless from && to
- first = project.commit(to.try(:strip))
- last = project.commit(from.try(:strip))
+ first = project.repository.commit(to.try(:strip))
+ last = project.repository.commit(from.try(:strip))
if first && last
result[:same] = (first.id == last.id)
@@ -98,6 +98,8 @@ class Commit
end
def initialize(raw_commit, head = nil)
+ raise "Nil as raw commit passed" unless raw_commit
+
@commit = raw_commit
@head = head
end
@@ -136,7 +138,11 @@ class Commit
end
def prev_commit
- parents.try :first
+ @prev_commit ||= if parents.present?
+ Commit.new(parents.first)
+ else
+ nil
+ end
end
def prev_commit_id
diff --git a/app/models/event.rb b/app/models/event.rb
index 95075ffae71..d0ba61544d1 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -110,26 +110,6 @@ class Event < ActiveRecord::Base
target_type == "MergeRequest"
end
- def new_issue?
- target_type == "Issue" &&
- action == Created
- end
-
- def new_merge_request?
- target_type == "MergeRequest" &&
- action == Created
- end
-
- def changed_merge_request?
- target_type == "MergeRequest" &&
- [Closed, Reopened].include?(action)
- end
-
- def changed_issue?
- target_type == "Issue" &&
- [Closed, Reopened].include?(action)
- end
-
def joined?
action == Joined
end
@@ -224,7 +204,7 @@ class Event < ActiveRecord::Base
# Max 20 commits from push DESC
def commits
- @commits ||= data[:commits].map { |commit| project.commit(commit[:id]) }.reverse
+ @commits ||= data[:commits].map { |commit| repository.commit(commit[:id]) }.reverse
end
def commits_count
@@ -245,14 +225,18 @@ class Event < ActiveRecord::Base
end
end
+ def repository
+ project.repository
+ end
+
def parent_commit
- project.commit(commit_from)
+ repository.commit(commit_from)
rescue => ex
nil
end
def last_commit
- project.commit(commit_to)
+ repository.commit(commit_to)
rescue => ex
nil
end
diff --git a/app/models/gitlab_ci_service.rb b/app/models/gitlab_ci_service.rb
index 0b0b65e2863..4eb39c7ef4d 100644
--- a/app/models/gitlab_ci_service.rb
+++ b/app/models/gitlab_ci_service.rb
@@ -29,10 +29,6 @@ class GitlabCiService < Service
hook.save
end
- def commit_badge_path sha
- project_url + "/status?sha=#{sha}"
- end
-
def commit_status_path sha
project_url + "/builds/#{sha}/status.json?token=#{token}"
end
diff --git a/app/models/note.rb b/app/models/note.rb
index 28b3879239f..abd89a8a46e 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -4,7 +4,6 @@
#
# id :integer not null, primary key
# note :text
-# noteable_id :string(255)
# noteable_type :string(255)
# author_id :integer
# created_at :datetime not null
@@ -12,6 +11,8 @@
# project_id :integer
# attachment :string(255)
# line_code :string(255)
+# commit_id :string(255)
+# noteable_id :integer
#
require 'carrierwave/orm/activerecord'
@@ -42,7 +43,7 @@ class Note < ActiveRecord::Base
# Scopes
scope :for_commits, ->{ where(noteable_type: "Commit") }
- scope :common, ->{ where(noteable_id: nil, commit_id: nil) }
+ scope :common, ->{ where(noteable_type: ["", nil]) }
scope :today, ->{ where("created_at >= :date", date: Date.today) }
scope :last_week, ->{ where("created_at >= :date", date: (Date.today - 7.days)) }
scope :since, ->(day) { where("created_at >= :date", date: (day)) }
@@ -70,7 +71,7 @@ class Note < ActiveRecord::Base
# override to return commits, which are not active record
def noteable
if for_commit?
- project.commit(commit_id)
+ project.repository.commit(commit_id)
else
super
end
diff --git a/app/models/project.rb b/app/models/project.rb
index f60c24426aa..2204d4a56e5 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -9,7 +9,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# private_flag :boolean default(TRUE), not null
-# owner_id :integer
+# creator_id :integer
# default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null
@@ -75,7 +75,6 @@ class Project < ActiveRecord::Base
validate :check_limit, :repo_name
# Scopes
- scope :public_only, where(private_flag: false)
scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }
scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) }
@@ -162,6 +161,20 @@ class Project < ActiveRecord::Base
end
end
+ def team
+ @team ||= Team.new(self)
+ end
+
+ def repository
+ if path
+ @repository ||= Repository.new(path_with_namespace, default_branch)
+ else
+ nil
+ end
+ rescue Grit::NoSuchPathError
+ nil
+ end
+
def git_error?
error_code == :gitolite
end
@@ -198,10 +211,6 @@ class Project < ActiveRecord::Base
[Gitlab.config.gitlab.url, path_with_namespace].join("/")
end
- def common_notes
- notes.where(noteable_type: ["", nil]).inc_author_project
- end
-
def build_commit_note(commit)
notes.new(commit_id: commit.id, noteable_type: "Commit")
end
@@ -214,14 +223,6 @@ class Project < ActiveRecord::Base
notes.where(commit_id: commit.id, noteable_type: "Commit").where("line_code IS NOT NULL")
end
- def public?
- !private_flag
- end
-
- def private?
- private_flag
- end
-
def last_activity
last_event
end
@@ -284,110 +285,6 @@ class Project < ActiveRecord::Base
users_projects.find_by_user_id(user_id)
end
- # Add user to project
- # with passed access role
- def add_user_to_team(user, access_role)
- add_user_id_to_team(user.id, access_role)
- end
-
- # Add multiple users to project
- # with same access role
- def add_users_to_team(users, access_role)
- add_users_ids_to_team(users.map(&:id), access_role)
- end
-
- # Add user to project
- # with passed access role by user id
- def add_user_id_to_team(user_id, access_role)
- users_projects.create(
- user_id: user_id,
- project_access: access_role
- )
- end
-
- # Add multiple users to project
- # with same access role by user ids
- def add_users_ids_to_team(users_ids, access_role)
- UsersProject.bulk_import(self, users_ids, access_role)
- end
-
- # Update multiple project users
- # to same access role by user ids
- def update_users_ids_to_role(users_ids, access_role)
- UsersProject.bulk_update(self, users_ids, access_role)
- end
-
- # Delete multiple users from project by user ids
- def delete_users_ids_from_team(users_ids)
- UsersProject.bulk_delete(self, users_ids)
- end
-
- # Remove all users from project team
- def truncate_team
- UsersProject.truncate_team(self)
- end
-
- # Compatible with all access rights
- # Should be rewrited for new access rights
- def add_access(user, *access)
- access = if access.include?(:admin)
- { project_access: UsersProject::MASTER }
- elsif access.include?(:write)
- { project_access: UsersProject::DEVELOPER }
- else
- { project_access: UsersProject::REPORTER }
- end
- opts = { user: user }
- opts.merge!(access)
- users_projects.create(opts)
- end
-
- def reset_access(user)
- users_projects.where(project_id: self.id, user_id: user.id).destroy if self.id
- end
-
- def repository_readers
- repository_members[UsersProject::REPORTER]
- end
-
- def repository_writers
- repository_members[UsersProject::DEVELOPER]
- end
-
- def repository_masters
- repository_members[UsersProject::MASTER]
- end
-
- def repository_members
- keys = Hash.new {|h,k| h[k] = [] }
- UsersProject.select("keys.identifier, project_access").
- joins(user: :keys).where(project_id: id).
- each {|row| keys[row.project_access] << [row.identifier] }
-
- keys[UsersProject::REPORTER] += deploy_keys.pluck(:identifier)
- keys
- end
-
- def allow_read_for?(user)
- !users_projects.where(user_id: user.id).empty?
- end
-
- def guest_access_for?(user)
- !users_projects.where(user_id: user.id).empty?
- end
-
- def report_access_for?(user)
- !users_projects.where(user_id: user.id, project_access: [UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
- end
-
- def dev_access_for?(user)
- !users_projects.where(user_id: user.id, project_access: [UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
- end
-
- def master_access_for?(user)
- !users_projects.where(user_id: user.id, project_access: [UsersProject::MASTER]).empty?
- end
-
def transfer(new_namespace)
Project.transaction do
old_namespace = namespace
@@ -464,8 +361,8 @@ class Project < ActiveRecord::Base
# Discover the default branch, but only if it hasn't already been set to
# something else
- if default_branch.nil?
- update_attributes(default_branch: discover_default_branch)
+ if repository && default_branch.nil?
+ update_attributes(default_branch: self.repository.discover_default_branch)
end
end
@@ -517,7 +414,7 @@ class Project < ActiveRecord::Base
#
def post_receive_data(oldrev, newrev, ref, user)
- push_commits = commits_between(oldrev, newrev)
+ push_commits = repository.commits_between(oldrev, newrev)
# Total commits count
push_commits_count = push_commits.size
@@ -564,7 +461,7 @@ class Project < ActiveRecord::Base
def update_merge_requests(oldrev, newrev, ref, user)
return true unless ref =~ /heads/
branch_name = ref.gsub("refs/heads/", "")
- c_ids = self.commits_between(oldrev, newrev).map(&:id)
+ c_ids = self.repository.commits_between(oldrev, newrev).map(&:id)
# Update code for merge requests
mrs = self.merge_requests.opened.find_all_by_branch(branch_name).all
@@ -586,97 +483,21 @@ class Project < ActiveRecord::Base
end
def empty_repo?
- !repo_exists? || !has_commits?
- end
-
- def commit(commit_id = nil)
- Commit.find_or_first(repo, commit_id, root_ref)
- end
-
- def fresh_commits(n = 10)
- Commit.fresh_commits(repo, n)
- end
-
- def commits_with_refs(n = 20)
- Commit.commits_with_refs(repo, n)
- end
-
- def commits_since(date)
- Commit.commits_since(repo, date)
- end
-
- def commits(ref, path = nil, limit = nil, offset = nil)
- Commit.commits(repo, ref, path, limit, offset)
- end
-
- def last_commit_for(ref, path = nil)
- commits(ref, path, 1).first
- end
-
- def commits_between(from, to)
- Commit.commits_between(repo, from, to)
+ !repository || repository.empty?
end
def satellite
@satellite ||= Gitlab::Satellite::Satellite.new(self)
end
- def has_post_receive_file?
- !!hook_file
- end
-
- def valid_post_receive_file?
- valid_hook_file == hook_file
- end
-
- def valid_hook_file
- @valid_hook_file ||= File.read(Rails.root.join('lib', 'hooks', 'post-receive'))
- end
-
- def hook_file
- @hook_file ||= begin
- hook_path = File.join(path_to_repo, 'hooks', 'post-receive')
- File.read(hook_path) if File.exists?(hook_path)
- end
- end
-
- # Returns an Array of branch names
- def branch_names
- repo.branches.collect(&:name).sort
- end
-
- # Returns an Array of Branches
- def branches
- repo.branches.sort_by(&:name)
- end
-
- # Returns an Array of tag names
- def tag_names
- repo.tags.collect(&:name).sort.reverse
- end
-
- # Returns an Array of Tags
- def tags
- repo.tags.sort_by(&:name).reverse
- end
-
- # Returns an Array of branch and tag names
- def ref_names
- [branch_names + tag_names].flatten
- end
-
def repo
- @repo ||= Grit::Repo.new(path_to_repo)
+ repository.raw
end
def url_to_repo
gitolite.url_to_repo(path_with_namespace)
end
- def path_to_repo
- File.join(Gitlab.config.gitolite.repos_path, "#{path_with_namespace}.git")
- end
-
def namespace_dir
namespace.try(:path) || ''
end
@@ -690,21 +511,11 @@ class Project < ActiveRecord::Base
end
def repo_exists?
- @repo_exists ||= (repo && !repo.branches.empty?)
+ @repo_exists ||= (repository && repository.branches.present?)
rescue
@repo_exists = false
end
- def heads
- @heads ||= repo.heads
- end
-
- def tree(fcommit, path = nil)
- fcommit = commit if fcommit == :head
- tree = fcommit.tree
- path ? (tree / path) : tree
- end
-
def open_branches
if protected_branches.empty?
self.repo.heads
@@ -714,61 +525,8 @@ class Project < ActiveRecord::Base
end.sort_by(&:name)
end
- # Discovers the default branch based on the repository's available branches
- #
- # - If no branches are present, returns nil
- # - If one branch is present, returns its name
- # - If two or more branches are present, returns the one that has a name
- # matching root_ref (default_branch or 'master' if default_branch is nil)
- def discover_default_branch
- if branch_names.length == 0
- nil
- elsif branch_names.length == 1
- branch_names.first
- else
- branch_names.select { |v| v == root_ref }.first
- end
- end
-
- def has_commits?
- !!commit
- rescue Grit::NoSuchPathError
- false
- end
-
- def root_ref
- default_branch || "master"
- end
-
def root_ref?(branch)
- root_ref == branch
- end
-
- # Archive Project to .tar.gz
- #
- # Already packed repo archives stored at
- # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz
- #
- def archive_repo(ref)
- ref = ref || self.root_ref
- commit = self.commit(ref)
- return nil unless commit
-
- # Build file path
- file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
- storage_path = Rails.root.join("tmp", "repositories", self.path_with_namespace)
- file_path = File.join(storage_path, file_name)
-
- # Put files into a directory before archiving
- prefix = self.path + "/"
-
- # Create file if not exists
- unless File.exists?(file_path)
- FileUtils.mkdir_p storage_path
- file = self.repo.archive_to_file(ref, prefix, file_path)
- end
-
- file_path
+ repository.root_ref == branch
end
def ssh_url_to_repo
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index f405a7bf7bc..3308caf360a 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -26,6 +26,6 @@ class ProtectedBranch < ActiveRecord::Base
end
def commit
- project.commit(self.name)
+ project.repository.commit(self.name)
end
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
new file mode 100644
index 00000000000..cf8ba4530a1
--- /dev/null
+++ b/app/models/repository.rb
@@ -0,0 +1,169 @@
+class Repository
+ # Repository directory name with namespace direcotry
+ # Examples:
+ # gitlab/gitolite
+ # diaspora
+ #
+ attr_accessor :path_with_namespace
+
+ # Grit repo object
+ attr_accessor :repo
+
+ # Default branch in the repository
+ attr_accessor :root_ref
+
+ def initialize(path_with_namespace, root_ref = 'master')
+ @root_ref = root_ref || "master"
+ @path_with_namespace = path_with_namespace
+
+ # Init grit repo object
+ repo
+ end
+
+ def raw
+ repo
+ end
+
+ def path_to_repo
+ @path_to_repo ||= File.join(Gitlab.config.gitolite.repos_path, "#{path_with_namespace}.git")
+ end
+
+ def repo
+ @repo ||= Grit::Repo.new(path_to_repo)
+ end
+
+ def commit(commit_id = nil)
+ Commit.find_or_first(repo, commit_id, root_ref)
+ end
+
+ def fresh_commits(n = 10)
+ Commit.fresh_commits(repo, n)
+ end
+
+ def commits_with_refs(n = 20)
+ Commit.commits_with_refs(repo, n)
+ end
+
+ def commits_since(date)
+ Commit.commits_since(repo, date)
+ end
+
+ def commits(ref, path = nil, limit = nil, offset = nil)
+ Commit.commits(repo, ref, path, limit, offset)
+ end
+
+ def last_commit_for(ref, path = nil)
+ commits(ref, path, 1).first
+ end
+
+ def commits_between(from, to)
+ Commit.commits_between(repo, from, to)
+ end
+
+ def has_post_receive_file?
+ !!hook_file
+ end
+
+ def valid_post_receive_file?
+ valid_hook_file == hook_file
+ end
+
+ def valid_hook_file
+ @valid_hook_file ||= File.read(Rails.root.join('lib', 'hooks', 'post-receive'))
+ end
+
+ def hook_file
+ @hook_file ||= begin
+ hook_path = File.join(path_to_repo, 'hooks', 'post-receive')
+ File.read(hook_path) if File.exists?(hook_path)
+ end
+ end
+
+ # Returns an Array of branch names
+ def branch_names
+ repo.branches.collect(&:name).sort
+ end
+
+ # Returns an Array of Branches
+ def branches
+ repo.branches.sort_by(&:name)
+ end
+
+ # Returns an Array of tag names
+ def tag_names
+ repo.tags.collect(&:name).sort.reverse
+ end
+
+ # Returns an Array of Tags
+ def tags
+ repo.tags.sort_by(&:name).reverse
+ end
+
+ # Returns an Array of branch and tag names
+ def ref_names
+ [branch_names + tag_names].flatten
+ end
+
+ def heads
+ @heads ||= repo.heads
+ end
+
+ def tree(fcommit, path = nil)
+ fcommit = commit if fcommit == :head
+ tree = fcommit.tree
+ path ? (tree / path) : tree
+ end
+
+ def has_commits?
+ !!commit
+ rescue Grit::NoSuchPathError
+ false
+ end
+
+ def empty?
+ !has_commits?
+ end
+
+ # Discovers the default branch based on the repository's available branches
+ #
+ # - If no branches are present, returns nil
+ # - If one branch is present, returns its name
+ # - If two or more branches are present, returns the one that has a name
+ # matching root_ref (default_branch or 'master' if default_branch is nil)
+ def discover_default_branch
+ if branch_names.length == 0
+ nil
+ elsif branch_names.length == 1
+ branch_names.first
+ else
+ branch_names.select { |v| v == root_ref }.first
+ end
+ end
+
+ # Archive Project to .tar.gz
+ #
+ # Already packed repo archives stored at
+ # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz
+ #
+ def archive_repo(ref)
+ ref = ref || self.root_ref
+ commit = self.commit(ref)
+ return nil unless commit
+
+ # Build file path
+ file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
+ storage_path = Rails.root.join("tmp", "repositories", self.path_with_namespace)
+ file_path = File.join(storage_path, file_name)
+
+ # Put files into a directory before archiving
+ prefix = self.path + "/"
+
+ # Create file if not exists
+ unless File.exists?(file_path)
+ FileUtils.mkdir_p storage_path
+ file = self.repo.archive_to_file(ref, prefix, file_path)
+ end
+
+ file_path
+ end
+end
diff --git a/app/models/team.rb b/app/models/team.rb
new file mode 100644
index 00000000000..f235d20ebdb
--- /dev/null
+++ b/app/models/team.rb
@@ -0,0 +1,118 @@
+class Team
+ attr_accessor :project
+
+ def initialize(project)
+ @project = project
+ end
+
+ # Shortcut to add users
+ #
+ # Use:
+ # @team << [@user, :master]
+ # @team << [@users, :master]
+ #
+ def << args
+ users = args.first
+
+ if users.respond_to?(:each)
+ add_users(users, args.second)
+ else
+ add_user(users, args.second)
+ end
+ end
+
+ def add_user(user, access)
+ add_users_ids([user.id], access)
+ end
+
+ def add_users(users, access)
+ add_users_ids(users.map(&:id), access)
+ end
+
+ def add_users_ids(user_ids, access)
+ UsersProject.add_users_into_projects(
+ [project.id],
+ user_ids,
+ access
+ )
+ end
+
+ # Remove all users from project team
+ def truncate
+ UsersProject.truncate_team(project)
+ end
+
+ def members
+ project.users_projects
+ end
+
+ def guests
+ members.guests.map(&:user)
+ end
+
+ def reporters
+ members.reporters.map(&:user)
+ end
+
+ def developers
+ members.developers.map(&:user)
+ end
+
+ def masters
+ members.masters.map(&:user)
+ end
+
+ def repository_readers
+ repository_members[UsersProject::REPORTER]
+ end
+
+ def repository_writers
+ repository_members[UsersProject::DEVELOPER]
+ end
+
+ def repository_masters
+ repository_members[UsersProject::MASTER]
+ end
+
+ def repository_members
+ keys = Hash.new {|h,k| h[k] = [] }
+ UsersProject.select("keys.identifier, project_access").
+ joins(user: :keys).where(project_id: project.id).
+ each {|row| keys[row.project_access] << [row.identifier] }
+
+ keys[UsersProject::REPORTER] += project.deploy_keys.pluck(:identifier)
+ keys
+ end
+
+ def import(source_project)
+ target_project = project
+
+ source_team = source_project.users_projects.all
+ target_team = target_project.users_projects.all
+ target_user_ids = target_team.map(&:user_id)
+
+ source_team.reject! do |tm|
+ # Skip if user already present in team
+ target_user_ids.include?(tm.user_id)
+ end
+
+ source_team.map! do |tm|
+ new_tm = tm.dup
+ new_tm.id = nil
+ new_tm.project_id = target_project.id
+ new_tm.skip_git = true
+ new_tm
+ end
+
+ UsersProject.transaction do
+ source_team.each do |tm|
+ tm.save
+ end
+ target_project.update_repository
+ end
+
+ true
+ rescue
+ false
+ end
+end
diff --git a/app/models/tree.rb b/app/models/tree.rb
index c3dfd4c718c..96395a42394 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -1,12 +1,13 @@
class Tree
include Linguist::BlobHelper
- attr_accessor :path, :tree, :project, :ref
+
+ attr_accessor :path, :tree, :ref
delegate :contents, :basename, :name, :data, :mime_type,
:mode, :size, :text?, :colorize, to: :tree
- def initialize(raw_tree, project, ref = nil, path = nil)
- @project, @ref, @path = project, ref, path
+ def initialize(raw_tree, ref = nil, path = nil)
+ @ref, @path = ref, path
@tree = if path.present?
raw_tree / path
else
diff --git a/app/models/user.rb b/app/models/user.rb
index d166ae4dc79..5e4815da865 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -188,7 +188,7 @@ class User < ActiveRecord::Base
# Team membership in personal projects
def tm_in_personal_projects
- personal_projects.users_projects.where(user_id: self.id)
+ UsersProject.where(project_id: personal_projects.map(&:id), user_id: self.id)
end
# Returns a string for use as a Gitolite user identifier
diff --git a/app/models/users_project.rb b/app/models/users_project.rb
index f8e0078400f..362b1a5d8e5 100644
--- a/app/models/users_project.rb
+++ b/app/models/users_project.rb
@@ -42,7 +42,34 @@ class UsersProject < ActiveRecord::Base
scope :in_project, ->(project) { where(project_id: project.id) }
class << self
- def add_users_into_projects(project_ids, user_ids, project_access)
+
+ # Add users to project teams with passed access option
+ #
+ # access can be an integer representing a access code
+ # or symbol like :master representing role
+ #
+ # Ex.
+ # add_users_into_projects(
+ # project_ids,
+ # user_ids,
+ # UsersProject::MASTER
+ # )
+ #
+ # add_users_into_projects(
+ # project_ids,
+ # user_ids,
+ # :master
+ # )
+ #
+ def add_users_into_projects(project_ids, user_ids, access)
+ project_access = if roles_hash.has_key?(access)
+ roles_hash[access]
+ elsif roles_hash.values.include?(access.to_i)
+ access
+ else
+ raise "Non valid access"
+ end
+
UsersProject.transaction do
project_ids.each do |project_id|
user_ids.each do |user_id|
@@ -79,36 +106,6 @@ class UsersProject < ActiveRecord::Base
truncate_teams [project.id]
end
- def import_team(source_project, target_project)
- source_team = source_project.users_projects.all
- target_team = target_project.users_projects.all
- target_user_ids = target_team.map(&:user_id)
-
- source_team.reject! do |tm|
- # Skip if user already present in team
- target_user_ids.include?(tm.user_id)
- end
-
- source_team.map! do |tm|
- new_tm = tm.dup
- new_tm.id = nil
- new_tm.project_id = target_project.id
- new_tm.skip_git = true
- new_tm
- end
-
- UsersProject.transaction do
- source_team.each do |tm|
- tm.save
- end
- target_project.update_repository
- end
-
- true
- rescue
- false
- end
-
def bulk_delete(project, user_ids)
UsersProject.transaction do
UsersProject.where(user_id: user_ids, project_id: project.id).each do |users_project|
@@ -131,14 +128,13 @@ class UsersProject < ActiveRecord::Base
end
end
- # TODO: depreceate in future in favor of add_users_into_projects
- def bulk_import(project, user_ids, project_access)
- add_users_into_projects([project.id], user_ids, project_access)
- end
-
- # TODO: depreceate in future in favor of add_users_into_projects
- def user_bulk_import(user, project_ids, project_access)
- add_users_into_projects(project_ids, [user.id], project_access)
+ def roles_hash
+ {
+ guest: GUEST,
+ reporter: REPORTER,
+ developer: DEVELOPER,
+ master: MASTER
+ }
end
def access_roles
diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb
index bb7dc0dab10..391731d9470 100644
--- a/app/uploaders/attachment_uploader.rb
+++ b/app/uploaders/attachment_uploader.rb
@@ -1,49 +1,13 @@
# encoding: utf-8
class AttachmentUploader < CarrierWave::Uploader::Base
-
- # Include RMagick or ImageScience support:
- # include CarrierWave::RMagick
- # include CarrierWave::MiniMagick
- # include CarrierWave::ImageScience
-
- # Choose what kind of storage to use for this uploader:
storage :file
- # storage :fog
- # Override the directory where uploaded files will be stored.
- # This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
- # Provide a default URL as a default if there hasn't been a file uploaded:
- # def default_url
- # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
- # end
-
- # Process files as they are uploaded:
- # process scale: [200, 300]
- #
- # def scale(width, height)
- # # do something
- # end
-
- # Create different versions of your uploaded files:
- # version :thumb do
- # process scale: [50, 50]
- # end
-
- # Add a white list of extensions which are allowed to be uploaded.
- # For images you might use something like this:
- # def extension_white_list
- # %w(jpg jpeg gif png)
- # end
-
- # Override the filename of the uploaded files:
- # Avoid using model.id or version_name here, see uploader/store.rb for details.
- # def filename
- # "something.jpg" if original_filename
- # end
-
+ def image?
+ %w(png jpg jpeg).include?(file.extension)
+ end
end
diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml
index 4320bda4999..672dad4377e 100644
--- a/app/views/admin/dashboard/index.html.haml
+++ b/app/views/admin/dashboard/index.html.haml
@@ -1,7 +1,7 @@
.admin_dash.row
.span3
.ui-box
- %h5 Projects
+ %h5.title Projects
.data.padded
= link_to admin_projects_path do
%h1= Project.count
@@ -9,7 +9,7 @@
= link_to 'New Project', new_project_path, class: "btn small"
.span3
.ui-box
- %h5 Groups
+ %h5.title Groups
.data.padded
= link_to admin_groups_path do
%h1= Group.count
@@ -17,7 +17,7 @@
= link_to 'New Group', new_admin_group_path, class: "btn small"
.span3
.ui-box
- %h5 Users
+ %h5.title Users
.data.padded
= link_to admin_users_path do
%h1= User.count
@@ -25,7 +25,7 @@
= link_to 'New User', new_admin_user_path, class: "btn small"
.span3
.ui-box
- %h5
+ %h5.title
Resque Workers
.data.padded
- if @resque_accessible
diff --git a/app/views/admin/projects/_form.html.haml b/app/views/admin/projects/_form.html.haml
index 27c22872d50..534c42223b3 100644
--- a/app/views/admin/projects/_form.html.haml
+++ b/app/views/admin/projects/_form.html.haml
@@ -22,7 +22,7 @@
- if project.repo_exists?
.clearfix
= f.label :default_branch, "Default Branch"
- .input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;")
+ .input= f.select(:default_branch, repository.heads.map(&:name), {}, style: "width:210px;")
%fieldset.adv_settings
%legend Features:
diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml
index ca9b9d3d444..5a745f58fe3 100644
--- a/app/views/admin/projects/show.html.haml
+++ b/app/views/admin/projects/show.html.haml
@@ -4,15 +4,15 @@
%i.icon-edit
Edit
-- if @project.has_commits?
- - if !@project.has_post_receive_file?
+- if @repository && @repository.has_commits?
+ - if !@repository.has_post_receive_file?
%br
.alert.alert-error
%span
%strong Project has commits but missing post-receive file.
%br
If you exported project manually - make a link of post-receive hook file from gitolite to project repository
- - elsif !@project.valid_post_receive_file?
+ - elsif !@repository.valid_post_receive_file?
%br
.alert.alert-error
%span
@@ -65,42 +65,43 @@
Created at:
%td
= @project.created_at.stamp("March 1, 1999")
+ %tr
+ %td
+ %b
+ Smart HTTP:
+ %td
+ = link_to @project.http_url_to_repo
+ %tr
+ %td
+ %b
+ SSH:
+ %td
+ = link_to @project.ssh_url_to_repo
-%table.zebra-striped
- %thead
+- if @repository
+ %table.zebra-striped
+ %thead
+ %tr
+ %th Repository
+ %th
%tr
- %th Repository
- %th
- %tr
- %td
- %b
- FS Path:
- %td
- %code= @project.path_to_repo
- %tr
- %td
- %b
- Smart HTTP:
- %td
- = link_to @project.http_url_to_repo
- %tr
- %td
- %b
- SSH:
- %td
- = link_to @project.ssh_url_to_repo
- %tr
- %td
- %b
- Last commit at:
- %td
- = last_commit(@project)
- %tr
- %td
- %b
- Post Receive File:
- %td
- = check_box_tag :post_receive_file, 1, @project.has_post_receive_file?, disabled: true
+ %td
+ %b
+ FS Path:
+ %td
+ %code= @repository.path_to_repo
+ %tr
+ %td
+ %b
+ Last commit at:
+ %td
+ = last_commit(@project)
+ %tr
+ %td
+ %b
+ Post Receive File:
+ %td
+ = check_box_tag :post_receive_file, 1, @repository.has_post_receive_file?, disabled: true
%br
%h5
diff --git a/app/views/commit/show.html.haml b/app/views/commit/show.html.haml
index 432d55b19e3..0144e4754c5 100644
--- a/app/views/commit/show.html.haml
+++ b/app/views/commit/show.html.haml
@@ -1,9 +1,15 @@
= render "commits/commit_box"
+
+%p.right.cgray
+ This commit has
+ %span.cgreen #{@commit.stats.additions} additions
+ and
+ %span.cred #{@commit.stats.deletions} deletions
+
= render "commits/diffs", diffs: @commit.diffs
= render "notes/notes_with_form", tid: @commit.id, tt: "commit"
= render "notes/per_line_form"
-
:javascript
$(function(){
PerLineNotes.init();
@@ -19,7 +25,7 @@
, h = event.currentTarget.naturalHeight;
$('.image.diff_added .image-info', this).append(' | <b>W:</b> ' + w + 'px | <b>H:</b> ' + h + 'px');
}, this));
-
+
});
-
+
});
diff --git a/app/views/commits/_commit_box.html.haml b/app/views/commits/_commit_box.html.haml
index 8f7826e0c8d..0544a1d10fe 100644
--- a/app/views/commits/_commit_box.html.haml
+++ b/app/views/commits/_commit_box.html.haml
@@ -1,47 +1,50 @@
-.commit-box{class: @commit.parents_count > 1 ? "merge-commit" : ""}
- .commit-head
+.ui-box.ui-box-show
+ .ui-box-head
.right
- if @notes_count > 0
%span.btn.disabled.grouped
%i.icon-comment
= @notes_count
.left.btn-group
- %a.btn.small.grouped.dropdown-toggle{ data: {toggle: :dropdown} }
+ %a.btn.grouped.dropdown-toggle{ data: {toggle: :dropdown} }
%i.icon-download-alt
Download as
%span.caret
%ul.dropdown-menu
%li= link_to "Email Patches", project_commit_path(@project, @commit, format: :patch)
%li= link_to "Plain Diff", project_commit_path(@project, @commit, format: :diff)
- = link_to project_tree_path(@project, @commit), class: "browse-button primary grouped" do
- %strong Browse Code »
+ = link_to project_tree_path(@project, @commit), class: "btn primary grouped" do
+ %span Browse Code »
%h3.commit-title.page_title
= gfm escape_once(@commit.title)
- if @commit.description.present?
%pre.commit-description
= gfm escape_once(@commit.description)
- .commit-info
+ .ui-box-body
.row
.span5
.author
- %strong= @commit.author_link avatar: true, size: 40
+ = @commit.author_link avatar: true, size: 32
authored
%time{title: @commit.authored_date.stamp("Aug 21, 2011 9:23pm")}
#{time_ago_in_words(@commit.authored_date)} ago
- if @commit.different_committer?
.committer
&rarr;
- %strong= @commit.committer_link
+ = @commit.committer_link
committed
%time{title: @commit.committed_date.stamp("Aug 21, 2011 9:23pm")}
#{time_ago_in_words(@commit.committed_date)} ago
- .span6.right
- .sha-block
- %span.cgray commit
- %code.label_commit= @commit.id
- .sha-block
- %span.cgray= pluralize(@commit.parents.count, "parent")
- - @commit.parents.each do |parent|
- = link_to parent.id[0...10], project_commit_path(@project, parent)
+ .span6.pull-right
+ .pull-right
+ .sha-block
+ %span.cgray commit
+ %span.label_commit= @commit.id
+ .clearfix
+ .pull-right
+ .sha-block
+ %span.cgray= pluralize(@commit.parents.count, "parent")
+ - @commit.parents.each do |parent|
+ = link_to parent.id[0...10], project_commit_path(@project, parent)
diff --git a/app/views/commits/_commits.html.haml b/app/views/commits/_commits.html.haml
index c9217989884..0dc6664c1d6 100644
--- a/app/views/commits/_commits.html.haml
+++ b/app/views/commits/_commits.html.haml
@@ -1,6 +1,6 @@
- @commits.group_by { |c| c.committed_date.to_date }.each do |day, commits|
%div.ui-box
- %h5.small
+ %h5.title
%i.icon-calendar
= day.stamp("28 Aug, 2010")
%ul.well-list= render commits
diff --git a/app/views/commits/_head.html.haml b/app/views/commits/_head.html.haml
index 2ec1d24bbef..a5f3fdf5c5e 100644
--- a/app/views/commits/_head.html.haml
+++ b/app/views/commits/_head.html.haml
@@ -2,19 +2,19 @@
%li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'}
= nav_link(controller: [:commit, :commits]) do
- = link_to 'Commits', project_commits_path(@project, @project.root_ref)
+ = link_to 'Commits', project_commits_path(@project, @repository.root_ref)
= nav_link(controller: :compare) do
= link_to 'Compare', project_compare_index_path(@project)
= nav_link(html_options: {class: branches_tab_class}) do
= link_to project_repository_path(@project) do
Branches
- %span.badge= @project.branches.length
+ %span.badge= @repository.branches.length
= nav_link(controller: :repositories, action: :tags) do
= link_to tags_project_repository_path(@project) do
Tags
- %span.badge= @project.tags.length
+ %span.badge= @repository.tags.length
= nav_link(controller: :repositories, action: :stats) do
= link_to stats_project_repository_path(@project) do
diff --git a/app/views/compare/_form.html.haml b/app/views/compare/_form.html.haml
index 7e3a2a0e1f5..0915782dddc 100644
--- a/app/views/compare/_form.html.haml
+++ b/app/views/compare/_form.html.haml
@@ -28,7 +28,7 @@
:javascript
$(function() {
- var availableTags = #{@project.ref_names.to_json};
+ var availableTags = #{@project.repository.ref_names.to_json};
$("#from, #to").autocomplete({
source: availableTags,
diff --git a/app/views/dashboard/_groups.html.haml b/app/views/dashboard/_groups.html.haml
index 5a95ab3fb98..7f544406761 100644
--- a/app/views/dashboard/_groups.html.haml
+++ b/app/views/dashboard/_groups.html.haml
@@ -1,5 +1,5 @@
.groups_box
- %h5
+ %h5.title
Groups
%small
(#{groups.count})
diff --git a/app/views/dashboard/_projects.html.haml b/app/views/dashboard/_projects.html.haml
index cffafb5445c..6c1304ee4a8 100644
--- a/app/views/dashboard/_projects.html.haml
+++ b/app/views/dashboard/_projects.html.haml
@@ -1,5 +1,5 @@
.projects_box
- %h5
+ %h5.title
Projects
%small
(#{projects.total_count})
diff --git a/app/views/dashboard/issues.html.haml b/app/views/dashboard/issues.html.haml
index 52863229644..68e3b3dcaf5 100644
--- a/app/views/dashboard/issues.html.haml
+++ b/app/views/dashboard/issues.html.haml
@@ -13,7 +13,8 @@
- @issues.group_by(&:project).each do |group|
%div.ui-box
- @project = group[0]
- %h5= link_to_project @project
+ %h5.title
+ = link_to_project @project
%ul.well-list.issues_table
- group[1].each do |issue|
= render(partial: 'issues/show', locals: {issue: issue})
diff --git a/app/views/dashboard/merge_requests.html.haml b/app/views/dashboard/merge_requests.html.haml
index ea7c8c9a3d5..c5245da731a 100644
--- a/app/views/dashboard/merge_requests.html.haml
+++ b/app/views/dashboard/merge_requests.html.haml
@@ -12,7 +12,8 @@
- @merge_requests.group_by(&:project).each do |group|
.ui-box
- @project = group[0]
- %h5= link_to_project @project
+ %h5.title
+ = link_to_project @project
%ul.well-list
- group[1].each do |merge_request|
= render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request})
diff --git a/app/views/groups/_projects.html.haml b/app/views/groups/_projects.html.haml
index 0b491879fe0..040d1ae94aa 100644
--- a/app/views/groups/_projects.html.haml
+++ b/app/views/groups/_projects.html.haml
@@ -1,5 +1,5 @@
.projects_box
- %h5
+ %h5.title
Projects
%small
(#{projects.count})
diff --git a/app/views/groups/issues.html.haml b/app/views/groups/issues.html.haml
index 0daf4d752a8..ebbe4df14fb 100644
--- a/app/views/groups/issues.html.haml
+++ b/app/views/groups/issues.html.haml
@@ -9,7 +9,8 @@
- @issues.group_by(&:project).each do |group|
%div.ui-box
- @project = group[0]
- %h5= @project.name
+ %h5.title
+ = @project.name
%ul.well-list.issues_table
- group[1].each do |issue|
= render(partial: 'issues/show', locals: {issue: issue})
diff --git a/app/views/groups/merge_requests.html.haml b/app/views/groups/merge_requests.html.haml
index 72aa4ad11e1..5fac4828526 100644
--- a/app/views/groups/merge_requests.html.haml
+++ b/app/views/groups/merge_requests.html.haml
@@ -8,7 +8,8 @@
- @merge_requests.group_by(&:project).each do |group|
%ul.well-list.ui-box
- @project = group[0]
- %h5= @project.name
+ %h5.title
+ = @project.name
- group[1].each do |merge_request|
= render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request})
%hr
diff --git a/app/views/groups/people.html.haml b/app/views/groups/people.html.haml
index 091f68756c3..0bceeaa3ceb 100644
--- a/app/views/groups/people.html.haml
+++ b/app/views/groups/people.html.haml
@@ -5,7 +5,7 @@
- if can?(current_user, :manage_group, @group)
= render (@project ? "new_member" : "new_group_member")
.ui-box
- %h5
+ %h5.title
Team
%small
(#{@users.size})
diff --git a/app/views/issues/_form.html.haml b/app/views/issues/_form.html.haml
index 030f797c088..02b11b53a95 100644
--- a/app/views/issues/_form.html.haml
+++ b/app/views/issues/_form.html.haml
@@ -6,26 +6,27 @@
- @issue.errors.full_messages.each do |msg|
%span= msg
%br
- .issue_form_box
- .issue_title
+ .ui-box.ui-box-show
+ .ui-box-head
.clearfix
= f.label :title do
%strong= "Subject *"
.input
= f.text_field :title, maxlength: 255, class: "xxlarge js-gfm-input", autofocus: true, required: true
- .issue_middle_block
- .issue_assignee
- = f.label :assignee_id do
- %i.icon-user
- Assign to
- .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select a user" }, {class: 'chosen'})
- .issue_milestone
- = f.label :milestone_id do
- %i.icon-time
- Milestone
- .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'})
+ .ui-box-body
+ .clearfix
+ .issue_assignee.pull-left
+ = f.label :assignee_id do
+ %i.icon-user
+ Assign to
+ .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select a user" }, {class: 'chosen'})
+ .issue_milestone.pull-left
+ = f.label :milestone_id do
+ %i.icon-time
+ Milestone
+ .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'})
- .issue_description
+ .ui-box-bottom
.clearfix
= f.label :label_list do
%i.icon-tag
diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml
index 08d4393b201..7971a124b80 100644
--- a/app/views/issues/index.html.haml
+++ b/app/views/issues/index.html.haml
@@ -30,7 +30,7 @@
= select_tag('update[milestone_id]', options_from_collection_for_select(issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone")
= hidden_field_tag 'update[issues_ids]', []
= hidden_field_tag :f, params[:f]
- = button_tag "Save", class: "btn update_selected_issues"
+ = button_tag "Save", class: "btn update_selected_issues btn-small save-btn"
.issues_filters
.left
%ul.nav.nav-pills.left
diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml
index 1d4d6a13c2b..544817192ab 100644
--- a/app/views/issues/show.html.haml
+++ b/app/views/issues/show.html.haml
@@ -24,14 +24,14 @@
&larr; To issues list
-.main_box
- .top_box_content
+.ui-box.ui-box-show
+ .ui-box-head
%h4.box-title
- if @issue.closed
.error.status_info Closed
= gfm escape_once(@issue.title)
- .middle_box_content
+ .ui-box-body
%cite.cgray
Created by #{link_to_member(@project, @issue.author)}
- if @issue.assignee
@@ -44,13 +44,13 @@
.right
- @issue.labels.each do |label|
- %span.label.label-issue
+ %span
%i.icon-tag
= label.name
&nbsp;
- if @issue.description.present?
- .bottom_box_content
+ .ui-box-bottom
= preserve do
= markdown @issue.description
diff --git a/app/views/layouts/project_resource.html.haml b/app/views/layouts/project_resource.html.haml
index 709807456c8..e00f96a7723 100644
--- a/app/views/layouts/project_resource.html.haml
+++ b/app/views/layouts/project_resource.html.haml
@@ -14,9 +14,9 @@
- if @project.repo_exists?
- if can? current_user, :download_code, @project
= nav_link(controller: %w(tree blob blame)) do
- = link_to 'Files', project_tree_path(@project, @ref || @project.root_ref)
+ = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref)
= nav_link(controller: %w(commit commits compare repositories protected_branches)) do
- = link_to "Commits", project_commits_path(@project, @ref || @project.root_ref)
+ = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref)
= nav_link(path: 'projects#graph') do
= link_to "Network", graph_project_path(@project)
diff --git a/app/views/merge_requests/_form.html.haml b/app/views/merge_requests/_form.html.haml
index 9606e2e53b3..67444dad5de 100644
--- a/app/views/merge_requests/_form.html.haml
+++ b/app/views/merge_requests/_form.html.haml
@@ -5,45 +5,47 @@
- @merge_request.errors.full_messages.each do |msg|
%li= msg
- %h4.cdark 1. Select Branches
- %br
+ %fieldset
+ %legend 1. Select Branches
- .row
- .span5
- .mr_branch_box
- %h5 From (Head Branch)
- .body
- .padded= f.select(:source_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'})
- .mr_source_commit
+ .row
+ .span5
+ .mr_branch_box
+ %h5 From (Head Branch)
+ .body
+ .padded= f.select(:source_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'})
+ .mr_source_commit
- .span2
- %center= image_tag "merge.png", class: 'mr_direction_tip'
- .span5
- .mr_branch_box
- %h5 To (Base Branch)
- .body
- .padded= f.select(:target_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'})
- .mr_target_commit
+ .span2
+ %center= image_tag "merge.png", class: 'mr_direction_tip'
+ .span5
+ .mr_branch_box
+ %h5 To (Base Branch)
+ .body
+ .padded= f.select(:target_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'})
+ .mr_target_commit
- %h4.cdark 2. Fill info
+ %fieldset
+ %legend 2. Fill info
- .clearfix
- .merge_requests_form_box
- .top_box_content
- = f.label :title do
- %strong= "Title *"
- .input= f.text_field :title, class: "input-xxlarge pad js-gfm-input", maxlength: 255, rows: 5, required: true
- .merge_requests_middle_box
- .merge_requests_assignee
- = f.label :assignee_id do
- %i.icon-user
- Assign to
- .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select user" }, {class: 'chosen span3'})
- .merge_requests_milestone
- = f.label :milestone_id do
- %i.icon-time
- Milestone
- .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'})
+ .ui-box.ui-box-show
+ .ui-box-head
+ .clearfix
+ = f.label :title do
+ %strong= "Title *"
+ .input= f.text_field :title, class: "input-xxlarge pad js-gfm-input", maxlength: 255, rows: 5, required: true
+ .ui-box-body
+ .clearfix
+ .left
+ = f.label :assignee_id do
+ %i.icon-user
+ Assign to
+ .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select user" }, {class: 'chosen span3'})
+ .left
+ = f.label :milestone_id do
+ %i.icon-time
+ Milestone
+ .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'})
.control-group
diff --git a/app/views/merge_requests/show/_commits.html.haml b/app/views/merge_requests/show/_commits.html.haml
index 796922776d9..40d85db0262 100644
--- a/app/views/merge_requests/show/_commits.html.haml
+++ b/app/views/merge_requests/show/_commits.html.haml
@@ -1,6 +1,6 @@
- if @commits.present?
.ui-box
- %h5
+ %h5.title
%i.icon-list
Commits (#{@commits.count})
.merge-request-commits
diff --git a/app/views/merge_requests/show/_mr_box.html.haml b/app/views/merge_requests/show/_mr_box.html.haml
index cd33732d191..644d7fcc58e 100644
--- a/app/views/merge_requests/show/_mr_box.html.haml
+++ b/app/views/merge_requests/show/_mr_box.html.haml
@@ -1,5 +1,5 @@
-.main_box
- .top_box_content
+.ui-box.ui-box-show
+ .ui-box-head
%h4.box-title
- if @merge_request.merged
.error.status_info
@@ -9,7 +9,7 @@
.error.status_info Closed
= gfm escape_once(@merge_request.title)
- .middle_box_content
+ .ui-box-body
%div
%cite.cgray
Created at #{@merge_request.created_at.stamp("Aug 21, 2011")} by #{link_to_member(@project, @merge_request.author)}
@@ -22,7 +22,7 @@
- if @merge_request.closed
- .bottom_box_content
+ .ui-box-bottom
- if @merge_request.merged?
%span
Merged by #{link_to_member(@project, @merge_request.merge_event.author)}
diff --git a/app/views/milestones/show.html.haml b/app/views/milestones/show.html.haml
index c4975c72ef2..6d276683fdc 100644
--- a/app/views/milestones/show.html.haml
+++ b/app/views/milestones/show.html.haml
@@ -27,8 +27,8 @@
%span All issues for this milestone are closed. You may close milestone now.
= link_to 'Close Milestone', project_milestone_path(@project, @milestone, milestone: {closed: true }), method: :put, class: "btn small danger"
-.main_box
- .top_box_content
+.ui-box.ui-box-show
+ .ui-box-head
%h4.box-title
- if @milestone.closed
.error.status_info Closed
@@ -37,7 +37,7 @@
= gfm escape_once(@milestone.title)
- .middle_box_content
+ .ui-box-body
%h5
Progress:
%small
diff --git a/app/views/notes/_note.html.haml b/app/views/notes/_note.html.haml
index 70baa212d10..8591e7bd86b 100644
--- a/app/views/notes/_note.html.haml
+++ b/app/views/notes/_note.html.haml
@@ -34,6 +34,8 @@
= preserve do
= markdown(note.note)
- if note.attachment.url
+ - if note.attachment.image?
+ = image_tag note.attachment.url, class: 'thumbnail span4'
.right
%div.file
= link_to note.attachment_identifier, note.attachment.url, target: "_blank"
diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml
index 7044d1f20be..c8eacdc2a46 100644
--- a/app/views/projects/_form.html.haml
+++ b/app/views/projects/_form.html.haml
@@ -15,13 +15,13 @@
= f.label :path do
Repository
.controls
- = text_field_tag :ppath, @project.path_to_repo, class: "xxlarge", readonly: true
+ = text_field_tag :ppath, @repository.path_to_repo, class: "xxlarge", readonly: true
- - unless @project.heads.empty?
+ - unless @repository.heads.empty?
.clearfix
= f.label :default_branch, "Default Branch"
- .input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;")
+ .input= f.select(:default_branch, @repository.heads.map(&:name), {}, style: "width:210px;")
%fieldset.features
%legend Features:
diff --git a/app/views/protected_branches/index.html.haml b/app/views/protected_branches/index.html.haml
index f408fd16c2c..098f8d55bb3 100644
--- a/app/views/protected_branches/index.html.haml
+++ b/app/views/protected_branches/index.html.haml
@@ -36,7 +36,7 @@
%td
= link_to project_commits_path(@project, branch.name) do
%strong= branch.name
- - if branch.name == @project.root_ref
+ - if @project.root_ref?(branch.name)
%span.label default
%td
- if branch.commit
diff --git a/app/views/repositories/_branch.html.haml b/app/views/repositories/_branch.html.haml
index 2728b100ff6..74f742687b1 100644
--- a/app/views/repositories/_branch.html.haml
+++ b/app/views/repositories/_branch.html.haml
@@ -8,7 +8,7 @@
- else
%i.icon-unlock
%strong= truncate(branch.name, length: 60)
- - if branch.name == @project.root_ref
+ - if branch.name == @repository.root_ref
%span.label default
%td
= link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do
diff --git a/app/views/repositories/_feed.html.haml b/app/views/repositories/_feed.html.haml
index 496328baca5..44380133718 100644
--- a/app/views/repositories/_feed.html.haml
+++ b/app/views/repositories/_feed.html.haml
@@ -5,7 +5,7 @@
= link_to project_commits_path(@project, commit.head.name) do
%strong
= commit.head.name
- - if commit.head.name == @project.root_ref
+ - if @project.root_ref?(commit.head.name)
%span.label default
%td
diff --git a/app/views/repositories/stats.html.haml b/app/views/repositories/stats.html.haml
index a93814a4777..bdf047f1e98 100644
--- a/app/views/repositories/stats.html.haml
+++ b/app/views/repositories/stats.html.haml
@@ -7,7 +7,7 @@
%b Total commits:
%span= @stats.commits_count
%p
- %b Total files in #{@project.root_ref}:
+ %b Total files in #{@repository.root_ref}:
%span= @stats.files_count
%p
%b Authors:
diff --git a/app/views/repositories/tags.html.haml b/app/views/repositories/tags.html.haml
index 193cb2e30f2..8e52ad1b47d 100644
--- a/app/views/repositories/tags.html.haml
+++ b/app/views/repositories/tags.html.haml
@@ -30,4 +30,10 @@
Download
- else
- %h3 No tags
+ %h3.nothing_here_message
+ Repository has no tags yet.
+ %br
+ %small
+ Use git tag command to add a new one:
+ %br
+ %span.monospace git tag -a v1.4 -m 'version 1.4'
diff --git a/app/views/team_members/_team.html.haml b/app/views/team_members/_team.html.haml
index 462e75af183..365d9b65942 100644
--- a/app/views/team_members/_team.html.haml
+++ b/app/views/team_members/_team.html.haml
@@ -1,6 +1,6 @@
- grouper_project_members(@project).each do |access, members|
.ui-box
- %h5
+ %h5.title
= Project.access_options.key(access).pluralize
%small= members.size
%ul.well-list
diff --git a/app/views/tree/_tree.html.haml b/app/views/tree/_tree.html.haml
index a632bb3b0d7..c2842959510 100644
--- a/app/views/tree/_tree.html.haml
+++ b/app/views/tree/_tree.html.haml
@@ -3,9 +3,13 @@
%span.arrow
= link_to project_tree_path(@project, @ref) do
= @project.name
- - tree.breadcrumbs(6) do |link|
+ - tree.breadcrumbs(6) do |title, path|
\/
- %li= link
+ %li
+ - if path
+ = link_to truncate(title, length: 40), project_tree_path(@project, path)
+ - else
+ = link_to title, '#'
.clear
%div.tree_progress
@@ -26,7 +30,7 @@
%tr.tree-item
%td.tree-item-file-name
= image_tag "file_empty.png", size: '16x16'
- = link_to "..", tree.up_dir_path
+ = link_to "..", project_tree_path(@project, tree.up_dir_path)
%td
%td
%td
diff --git a/app/views/wikis/_form.html.haml b/app/views/wikis/_form.html.haml
index 83b16b138d3..9eb2a571fe5 100644
--- a/app/views/wikis/_form.html.haml
+++ b/app/views/wikis/_form.html.haml
@@ -6,12 +6,12 @@
- @wiki.errors.full_messages.each do |msg|
%li= msg
- .main_box
- .top_box_content
+ .ui-box.ui-box-show
+ .ui-box-head
= f.label :title
.input= f.text_field :title, class: 'span8'
= f.hidden_field :slug
- .middle_box_content
+ .ui-box-body
.input
%span.cgray
Wiki content is parsed with #{link_to "GitLab Flavored Markdown", help_markdown_path, target: '_blank'}.
@@ -19,7 +19,7 @@
%code [Link Title](page-slug)
\.
- .bottom_box_content
+ .ui-box-bottom
= f.label :content
.input= f.text_area :content, class: 'span8 js-gfm-input'
.actions
diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb
index 1414ed490c9..9e3f32f835d 100644
--- a/app/workers/post_receive.rb
+++ b/app/workers/post_receive.rb
@@ -11,7 +11,7 @@ class PostReceive
# Ignore push from non-gitlab users
user = if identifier.eql? Gitlab.config.gitolite.admin_key
- email = project.commit(newrev).author.email rescue nil
+ email = project.repository.commit(newrev).author.email rescue nil
User.find_by_email(email) if email
elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
User.find_by_email(identifier)
diff --git a/features/steps/admin/admin_groups.rb b/features/steps/admin/admin_groups.rb
index 4cd071657fe..cbca2daa701 100644
--- a/features/steps/admin/admin_groups.rb
+++ b/features/steps/admin/admin_groups.rb
@@ -16,7 +16,7 @@ class AdminGroups < Spinach::FeatureSteps
@project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project)
- @project.add_access current_user, :admin
+ @project.team << [current_user, :master]
end
And 'Create gitlab user "John"' do
diff --git a/features/steps/dashboard/dashboard.rb b/features/steps/dashboard/dashboard.rb
index 775a721f1a4..73e22673749 100644
--- a/features/steps/dashboard/dashboard.rb
+++ b/features/steps/dashboard/dashboard.rb
@@ -61,7 +61,7 @@ class Dashboard < Spinach::FeatureSteps
And 'I own project "Shop"' do
@project = create :project, name: 'Shop'
- @project.add_access(@user, :admin)
+ @project.team << [@user, :master]
end
And 'I have group with projects' do
@@ -69,7 +69,7 @@ class Dashboard < Spinach::FeatureSteps
@project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project)
- @project.add_access current_user, :admin
+ @project.team << [current_user, :master]
end
And 'project "Shop" has push event' do
diff --git a/features/steps/dashboard/dashboard_issues.rb b/features/steps/dashboard/dashboard_issues.rb
index 5ace88023f0..fcf4296ad11 100644
--- a/features/steps/dashboard/dashboard_issues.rb
+++ b/features/steps/dashboard/dashboard_issues.rb
@@ -13,7 +13,7 @@ class DashboardIssues < Spinach::FeatureSteps
And 'I have assigned issues' do
project = create :project
- project.add_access(@user, :read, :write)
+ project.team << [@user, :master]
2.times { create :issue, author: @user, assignee: @user, project: project }
end
diff --git a/features/steps/dashboard/dashboard_merge_requests.rb b/features/steps/dashboard/dashboard_merge_requests.rb
index 485a4ccc113..7cfa8a13ff8 100644
--- a/features/steps/dashboard/dashboard_merge_requests.rb
+++ b/features/steps/dashboard/dashboard_merge_requests.rb
@@ -14,8 +14,8 @@ class DashboardMergeRequests < Spinach::FeatureSteps
project1 = create :project
project2 = create :project
- project1.add_access(@user, :read, :write)
- project2.add_access(@user, :read, :write)
+ project1.team << [@user, :master]
+ project2.team << [@user, :master]
merge_request1 = create :merge_request, author: @user, project: project1
merge_request2 = create :merge_request, author: @user, project: project2
diff --git a/features/steps/dashboard/dashboard_search.rb b/features/steps/dashboard/dashboard_search.rb
index a34c14d0c5f..9c8c879479d 100644
--- a/features/steps/dashboard/dashboard_search.rb
+++ b/features/steps/dashboard/dashboard_search.rb
@@ -1,6 +1,7 @@
class DashboardSearch < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
+ include SharedProject
Given 'I search for "Sho"' do
fill_in "dashboard_search", with: "Sho"
@@ -11,11 +12,6 @@ class DashboardSearch < Spinach::FeatureSteps
page.should have_link "Shop"
end
- And 'I own project "Shop"' do
- @project = create(:project, :name => "Shop")
- @project.add_access(@user, :admin)
- end
-
Given 'I search for "Contibuting"' do
fill_in "dashboard_search", with: "Contibuting"
click_button "Search"
diff --git a/features/steps/group/group.rb b/features/steps/group/group.rb
index e3364f09e34..04d8c874b3e 100644
--- a/features/steps/group/group.rb
+++ b/features/steps/group/group.rb
@@ -13,7 +13,7 @@ class Groups < Spinach::FeatureSteps
@project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project)
- @project.add_access current_user, :admin
+ @project.team << [current_user, :master]
end
And 'I should see projects activity feed' do
diff --git a/features/steps/project/create_project.rb b/features/steps/project/create_project.rb
index b9b4534ed68..0d9727732c7 100644
--- a/features/steps/project/create_project.rb
+++ b/features/steps/project/create_project.rb
@@ -3,13 +3,13 @@ class CreateProject < Spinach::FeatureSteps
include SharedPaths
And 'fill project form with valid data' do
- fill_in 'project_name', :with => 'NewProject'
+ fill_in 'project_name', with: 'Empty'
click_button "Create project"
end
Then 'I should see project page' do
current_path.should == project_path(Project.last)
- page.should have_content "NewProject"
+ page.should have_content "Empty"
end
And 'I should see empty project instuctions' do
diff --git a/features/steps/project/project_browse_commits.rb b/features/steps/project/project_browse_commits.rb
index 2c03ce14fc1..3433c2ba5f6 100644
--- a/features/steps/project/project_browse_commits.rb
+++ b/features/steps/project/project_browse_commits.rb
@@ -4,7 +4,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
include SharedPaths
Then 'I see project commits' do
- commit = @project.commit
+ commit = @project.repository.commit
page.should have_content(@project.name)
page.should have_content(commit.message)
page.should have_content(commit.id.to_s[0..5])
@@ -15,7 +15,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
end
Then 'I see commits atom feed' do
- commit = CommitDecorator.decorate(@project.commit)
+ commit = CommitDecorator.decorate(@project.repository.commit)
page.response_headers['Content-Type'].should have_content("application/atom+xml")
page.body.should have_selector("title", :text => "Recent commits to #{@project.name}")
page.body.should have_selector("author email", :text => commit.author_email)
@@ -48,7 +48,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
page.should have_selector('ul.breadcrumb span.divider', count: 3)
page.should have_selector('ul.breadcrumb a', count: 4)
- find('ul.breadcrumb li:first a')['href'].should match(/#{@project.path}\/commits\/master\z/)
+ find('ul.breadcrumb li:first a')['href'].should match(/#{@project.path_with_namespace}\/commits\/master\z/)
find('ul.breadcrumb li:last a')['href'].should match(%r{master/app/models/project\.rb\z})
end
diff --git a/features/steps/project/project_team_management.rb b/features/steps/project/project_team_management.rb
index 6bde0b64dfa..91b3ffeee9a 100644
--- a/features/steps/project/project_team_management.rb
+++ b/features/steps/project/project_team_management.rb
@@ -84,18 +84,18 @@ class ProjectTeamManagement < Spinach::FeatureSteps
And '"Sam" is "Shop" developer' do
user = User.find_by_name("Sam")
project = Project.find_by_name("Shop")
- project.add_access(user, :write)
+ project.team << [user, :developer]
end
Given 'I own project "Website"' do
@project = create(:project, :name => "Website")
- @project.add_access(@user, :admin)
+ @project.team << [@user, :master]
end
And '"Mike" is "Website" reporter' do
user = User.find_by_name("Mike")
project = Project.find_by_name("Website")
- project.add_access(user, :read)
+ project.team << [user, :reporter]
end
And 'I click link "Import team from another project"' do
diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb
index bd43ba6b3dc..22d1f335063 100644
--- a/features/steps/shared/paths.rb
+++ b/features/steps/shared/paths.rb
@@ -114,15 +114,15 @@ module SharedPaths
end
Given "I visit my project's files page" do
- visit project_tree_path(@project, @project.root_ref)
+ visit project_tree_path(@project, root_ref)
end
Given "I visit my project's commits page" do
- visit project_commits_path(@project, @project.root_ref, {limit: 5})
+ visit project_commits_path(@project, root_ref, {limit: 5})
end
Given "I visit my project's commits page for a specific path" do
- visit project_commits_path(@project, @project.root_ref + "/app/models/project.rb", {limit: 5})
+ visit project_commits_path(@project, root_ref + "/app/models/project.rb", {limit: 5})
end
Given 'I visit my project\'s commits stats page' do
@@ -174,7 +174,7 @@ module SharedPaths
end
Given 'I visit project commits page' do
- visit project_commits_path(@project, @project.root_ref, {limit: 5})
+ visit project_commits_path(@project, root_ref, {limit: 5})
end
Given 'I visit project commits page for stable branch' do
@@ -182,7 +182,7 @@ module SharedPaths
end
Given 'I visit project source page' do
- visit project_tree_path(@project, @project.root_ref)
+ visit project_tree_path(@project, root_ref)
end
Given 'I visit blob file from repo' do
@@ -240,4 +240,8 @@ module SharedPaths
Given 'I visit project wiki page' do
visit project_wiki_path(@project, :index)
end
+
+ def root_ref
+ @project.repository.root_ref
+ end
end
diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb
index dfc8ce9d99c..12dae15edf9 100644
--- a/features/steps/shared/project.rb
+++ b/features/steps/shared/project.rb
@@ -4,13 +4,13 @@ module SharedProject
# Create a project without caring about what it's called
And "I own a project" do
@project = create(:project)
- @project.add_access(@user, :admin)
+ @project.team << [@user, :master]
end
# Create a specific project called "Shop"
And 'I own project "Shop"' do
- @project = create(:project, :name => "Shop")
- @project.add_access(@user, :admin)
+ @project = create(:project, name: "Shop")
+ @project.team << [@user, :master]
end
def current_project
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index 4875ac4c03e..4613db54578 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -13,7 +13,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/notes
get ":id/notes" do
- @notes = user_project.common_notes
+ @notes = user_project.notes.common
present paginate(@notes), with: Entities::Note
end
@@ -25,7 +25,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/notes/:note_id
get ":id/notes/:note_id" do
- @note = user_project.common_notes.find(params[:note_id])
+ @note = user_project.notes.common.find(params[:note_id])
present @note, with: Entities::Note
end
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index c71fd64838b..55c81f3158a 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -257,7 +257,7 @@ module Gitlab
per_page = params[:per_page] || 20
ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
- commits = user_project.commits(ref, nil, per_page, page * per_page)
+ commits = user_project.repository.commits(ref, nil, per_page, page * per_page)
present CommitDecorator.decorate(commits), with: Entities::RepoCommit
end
@@ -375,10 +375,10 @@ module Gitlab
ref = params[:sha]
- commit = user_project.commit ref
+ commit = user_project.repository.commit ref
not_found! "Commit" unless commit
- tree = Tree.new commit.tree, user_project, ref, params[:filepath]
+ tree = Tree.new commit.tree, ref, params[:filepath]
not_found! "File" unless tree.try(:tree)
content_type tree.mime_type
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 0b7a0d47caf..5c96eac02e7 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -68,7 +68,7 @@ module ExtractsPath
id = input
id += '/' unless id.ends_with?('/')
- valid_refs = @project.ref_names
+ valid_refs = @project.repository.ref_names
valid_refs.select! { |v| id.start_with?("#{v}/") }
if valid_refs.length != 1
@@ -114,9 +114,9 @@ module ExtractsPath
@id = File.join(@ref, @path)
- @commit = CommitDecorator.decorate(@project.commit(@ref))
+ @commit = CommitDecorator.decorate(@project.repository.commit(@ref))
- @tree = Tree.new(@commit.tree, @project, @ref, @path)
+ @tree = Tree.new(@commit.tree, @ref, @path)
@tree = TreeDecorator.new(@tree)
raise InvalidPathError if @tree.invalid?
diff --git a/lib/gitlab/backend/gitolite_config.rb b/lib/gitlab/backend/gitolite_config.rb
index a2bc4ca8d74..10e527eac73 100644
--- a/lib/gitlab/backend/gitolite_config.rb
+++ b/lib/gitlab/backend/gitolite_config.rb
@@ -82,7 +82,7 @@ module Gitlab
end
def destroy_project(project)
- FileUtils.rm_rf(project.path_to_repo)
+ FileUtils.rm_rf(project.repository.path_to_repo)
conf.rm_repo(project.path_with_namespace)
end
@@ -138,9 +138,9 @@ module Gitlab
::Gitolite::Config::Repo.new(repo_name)
end
- name_readers = project.repository_readers
- name_writers = project.repository_writers
- name_masters = project.repository_masters
+ name_readers = project.team.repository_readers
+ name_writers = project.team.repository_writers
+ name_masters = project.team.repository_masters
pr_br = project.protected_branches.map(&:name).join("$ ")
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb
index 859184b6c3a..59249a229eb 100644
--- a/lib/gitlab/markdown.rb
+++ b/lib/gitlab/markdown.rb
@@ -170,7 +170,7 @@ module Gitlab
end
def reference_commit(identifier)
- if @project.valid_repo? && commit = @project.commit(identifier)
+ if @project.valid_repo? && commit = @project.repository.commit(identifier)
link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}"))
end
end
diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb
index 832db6621c4..556a1e2d52f 100644
--- a/lib/gitlab/satellite/merge_action.rb
+++ b/lib/gitlab/satellite/merge_action.rb
@@ -31,7 +31,7 @@ module Gitlab
merge_repo.git.push({raise: true, timeout: true}, :origin, merge_request.target_branch)
# remove source branch
- if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch)
+ if merge_request.should_remove_source_branch && !project.repository.root_ref?(merge_request.source_branch)
# will raise CommandFailed when push fails
merge_repo.git.push({raise: true, timeout: true}, :origin, ":#{merge_request.source_branch}")
end
diff --git a/lib/static_model.rb b/lib/static_model.rb
index 5b64be1f041..185921d8fbe 100644
--- a/lib/static_model.rb
+++ b/lib/static_model.rb
@@ -38,7 +38,7 @@ module StaticModel
end
def ==(other)
- if other.is_a? StaticModel
+ if other.is_a? ::StaticModel
id == other.id
else
super
diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb
index 5aef4c676ee..7bf13822829 100644
--- a/spec/controllers/commit_controller_spec.rb
+++ b/spec/controllers/commit_controller_spec.rb
@@ -3,12 +3,12 @@ require 'spec_helper'
describe CommitController do
let(:project) { create(:project) }
let(:user) { create(:user) }
- let(:commit) { project.last_commit_for("master") }
+ let(:commit) { project.repository.last_commit_for("master") }
before do
sign_in(user)
- project.add_access(user, :read, :admin)
+ project.team << [user, :master]
end
describe "#show" do
diff --git a/spec/controllers/commits_controller_spec.rb b/spec/controllers/commits_controller_spec.rb
index da33fd8a2b5..1d5d99df802 100644
--- a/spec/controllers/commits_controller_spec.rb
+++ b/spec/controllers/commits_controller_spec.rb
@@ -7,7 +7,7 @@ describe CommitsController do
before do
sign_in(user)
- project.add_access(user, :read, :admin)
+ project.team << [user, :master]
end
describe "GET show" do
diff --git a/spec/controllers/merge_requests_controller_spec.rb b/spec/controllers/merge_requests_controller_spec.rb
index 7aebe06cf0c..8478bb3adff 100644
--- a/spec/controllers/merge_requests_controller_spec.rb
+++ b/spec/controllers/merge_requests_controller_spec.rb
@@ -7,7 +7,7 @@ describe MergeRequestsController do
before do
sign_in(user)
- project.add_access(user, :read, :admin)
+ project.team << [user, :master]
MergeRequestsController.any_instance.stub(validates_merge_request: true)
end
diff --git a/spec/controllers/tree_controller_spec.rb b/spec/controllers/tree_controller_spec.rb
index b9295537d01..81c7656d07a 100644
--- a/spec/controllers/tree_controller_spec.rb
+++ b/spec/controllers/tree_controller_spec.rb
@@ -7,7 +7,7 @@ describe TreeController do
before do
sign_in(user)
- project.add_access(user, :read, :admin)
+ project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index b792e0c86f6..497a5f17846 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -4,7 +4,7 @@ describe GitlabMarkdownHelper do
let!(:project) { create(:project) }
let(:user) { create(:user, username: 'gfm') }
- let(:commit) { CommitDecorator.decorate(project.commit) }
+ let(:commit) { CommitDecorator.decorate(project.repository.commit) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, project: project) }
let(:snippet) { create(:snippet, project: project) }
@@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do
let(:expected) { project_team_member_path(project, member) }
before do
- project.add_access(user, :admin)
+ project.team << [user, :master]
end
it "should link using a simple name" do
@@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do
end
it "should handle references in lists" do
- project.add_access(user, :admin)
+ project.team << [user, :master]
actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}"
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index 8773d77f5a5..deb6499e008 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -7,7 +7,7 @@ describe ExtractsPath do
before do
@project = project
- project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])
+ project.stub(repository: stub(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']))
project.stub(path_with_namespace: 'gitlab/gitlab-ci')
end
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index e760c501bd7..91301029e89 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Commit do
- let(:commit) { create(:project).commit }
+ let(:commit) { create(:project).repository.commit }
describe CommitDecorator do
let(:decorator) { CommitDecorator.new(commit) }
diff --git a/spec/models/gitlab_ci_service_spec.rb b/spec/models/gitlab_ci_service_spec.rb
index ec43d46b347..b86588af1ac 100644
--- a/spec/models/gitlab_ci_service_spec.rb
+++ b/spec/models/gitlab_ci_service_spec.rb
@@ -35,10 +35,6 @@ describe GitlabCiService do
)
end
- describe :commit_badge_path do
- it { @service.commit_badge_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/status?sha=2ab7834c"}
- end
-
describe :commit_status_path do
it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c/status.json?token=verySecret"}
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 61aaf6455eb..8e06e6748da 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -4,7 +4,6 @@
#
# id :integer not null, primary key
# note :text
-# noteable_id :string(255)
# noteable_type :string(255)
# author_id :integer
# created_at :datetime not null
@@ -12,6 +11,8 @@
# project_id :integer
# attachment :string(255)
# line_code :string(255)
+# commit_id :string(255)
+# noteable_id :integer
#
require 'spec_helper'
@@ -76,7 +77,7 @@ describe Note do
end
let(:project) { create(:project) }
- let(:commit) { project.commit }
+ let(:commit) { project.repository.commit }
describe "Commit notes" do
before do
diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb
index 77adfe06cff..60457e20c51 100644
--- a/spec/models/project_hooks_spec.rb
+++ b/spec/models/project_hooks_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe Project, "Hooks" do
let(:project) { create(:project) }
+
before do
@key = create(:key, user: project.owner)
@user = @key.user
@@ -70,8 +71,9 @@ describe Project, "Hooks" do
context "when gathering commit data" do
before do
- @oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
- @commit = project.fresh_commits(2).first
+ @oldrev, @newrev, @ref = project.repository.fresh_commits(2).last.sha,
+ project.repository.fresh_commits(2).first.sha, 'refs/heads/master'
+ @commit = project.repository.fresh_commits(2).first
# Fill nil/empty attributes
project.description = "This is a description"
diff --git a/spec/models/project_repository_spec.rb b/spec/models/project_repository_spec.rb
deleted file mode 100644
index e1d01cbfeaf..00000000000
--- a/spec/models/project_repository_spec.rb
+++ /dev/null
@@ -1,159 +0,0 @@
-require 'spec_helper'
-
-describe Project, "Repository" do
- let(:project) { create(:project) }
-
- describe "#empty_repo?" do
- it "should return true if the repo doesn't exist" do
- project.stub(repo_exists?: false, has_commits?: true)
- project.should be_empty_repo
- end
-
- it "should return true if the repo has commits" do
- project.stub(repo_exists?: true, has_commits?: false)
- project.should be_empty_repo
- end
-
- it "should return false if the repo exists and has commits" do
- project.stub(repo_exists?: true, has_commits?: true)
- project.should_not be_empty_repo
- end
- end
-
- describe "#discover_default_branch" do
- let(:master) { 'master' }
- let(:stable) { 'stable' }
-
- it "returns 'master' when master exists" do
- project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
- project.discover_default_branch.should == 'master'
- end
-
- it "returns non-master when master exists but default branch is set to something else" do
- project.default_branch = 'stable'
- project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
- project.discover_default_branch.should == 'stable'
- end
-
- it "returns a non-master branch when only one exists" do
- project.should_receive(:branch_names).at_least(:once).and_return([stable])
- project.discover_default_branch.should == 'stable'
- end
-
- it "returns nil when no branch exists" do
- project.should_receive(:branch_names).at_least(:once).and_return([])
- project.discover_default_branch.should be_nil
- end
- end
-
- describe "#root_ref" do
- it "returns default_branch when set" do
- project.default_branch = 'stable'
- project.root_ref.should == 'stable'
- end
-
- it "returns 'master' when default_branch is nil" do
- project.default_branch = nil
- project.root_ref.should == 'master'
- end
- end
-
- describe "#root_ref?" do
- it "returns true when branch is root_ref" do
- project.default_branch = 'stable'
- project.root_ref?('stable').should be_true
- end
-
- it "returns false when branch is not root_ref" do
- project.default_branch = nil
- project.root_ref?('stable').should be_false
- end
- end
-
- describe :repo do
- it "should return valid repo" do
- project.repo.should be_kind_of(Grit::Repo)
- end
-
- it "should return nil" do
- lambda { Project.new(path: "invalid").repo }.should raise_error(Grit::NoSuchPathError)
- end
-
- it "should return nil" do
- lambda { Project.new.repo }.should raise_error(TypeError)
- end
- end
-
- describe :commit do
- it "should return first head commit if without params" do
- project.commit.id.should == project.repo.commits.first.id
- end
-
- it "should return valid commit" do
- project.commit(ValidCommit::ID).should be_valid_commit
- end
-
- it "should return nil" do
- project.commit("+123_4532530XYZ").should be_nil
- end
- end
-
- describe :tree do
- before do
- @commit = project.commit(ValidCommit::ID)
- end
-
- it "should raise error w/o arguments" do
- lambda { project.tree }.should raise_error
- end
-
- it "should return root tree for commit" do
- tree = project.tree(@commit)
- tree.contents.size.should == ValidCommit::FILES_COUNT
- tree.contents.map(&:name).should == ValidCommit::FILES
- end
-
- it "should return root tree for commit with correct path" do
- tree = project.tree(@commit, ValidCommit::C_FILE_PATH)
- tree.contents.map(&:name).should == ValidCommit::C_FILES
- end
-
- it "should return root tree for commit with incorrect path" do
- project.tree(@commit, "invalid_path").should be_nil
- end
- end
-
- describe "fresh commits" do
- let(:project) { create(:project) }
-
- it { project.fresh_commits(3).count.should == 3 }
- it { project.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
- it { project.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
- end
-
- describe "commits_between" do
- let(:project) { create(:project) }
-
- subject do
- commits = project.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
- "8470d70da67355c9c009e4401746b1d5410af2e3")
- commits.map { |c| c.id }
- end
-
- it { should have(3).elements }
- it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
- it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
- end
-
- describe :valid_repo? do
- it "should be valid repo" do
- project = create(:project)
- project.valid_repo?.should be_true
- end
-
- it "should be invalid repo" do
- project = Project.new(name: "ok_name", path: "/INVALID_PATH/", path: "NEOK")
- project.valid_repo?.should be_false
- end
- end
-end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ea1efbbec78..223b9d48c01 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -9,7 +9,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# private_flag :boolean default(TRUE), not null
-# owner_id :integer
+# creator_id :integer
# default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null
@@ -75,57 +75,16 @@ describe Project do
end
describe "Respond to" do
- it { should respond_to(:public?) }
- it { should respond_to(:private?) }
it { should respond_to(:url_to_repo) }
- it { should respond_to(:path_to_repo) }
- it { should respond_to(:valid_repo?) }
it { should respond_to(:repo_exists?) }
-
- # Repository Role
- it { should respond_to(:tree) }
- it { should respond_to(:root_ref) }
- it { should respond_to(:repo) }
- it { should respond_to(:tags) }
- it { should respond_to(:commit) }
- it { should respond_to(:commits) }
- it { should respond_to(:commits_between) }
- it { should respond_to(:commits_with_refs) }
- it { should respond_to(:commits_since) }
- it { should respond_to(:commits_between) }
it { should respond_to(:satellite) }
it { should respond_to(:update_repository) }
it { should respond_to(:destroy_repository) }
- it { should respond_to(:archive_repo) }
-
- # Authority Role
- it { should respond_to(:add_access) }
- it { should respond_to(:reset_access) }
- it { should respond_to(:repository_writers) }
- it { should respond_to(:repository_masters) }
- it { should respond_to(:repository_readers) }
- it { should respond_to(:allow_read_for?) }
- it { should respond_to(:guest_access_for?) }
- it { should respond_to(:report_access_for?) }
- it { should respond_to(:dev_access_for?) }
- it { should respond_to(:master_access_for?) }
-
- # Team Role
- it { should respond_to(:team_member_by_name_or_email) }
- it { should respond_to(:team_member_by_id) }
- it { should respond_to(:add_user_to_team) }
- it { should respond_to(:add_users_to_team) }
- it { should respond_to(:add_user_id_to_team) }
- it { should respond_to(:add_users_ids_to_team) }
-
- # Project Push Role
it { should respond_to(:observe_push) }
it { should respond_to(:update_merge_requests) }
it { should respond_to(:execute_hooks) }
it { should respond_to(:post_receive_data) }
it { should respond_to(:trigger_post_receive) }
-
- # Namespaced Project Role
it { should respond_to(:transfer) }
it { should respond_to(:name_with_namespace) }
it { should respond_to(:namespace_owner) }
@@ -138,11 +97,6 @@ describe Project do
project.url_to_repo.should == Gitlab.config.gitolite.ssh_path_prefix + "somewhere.git"
end
- it "should return path to repo" do
- project = Project.new(path: "somewhere")
- project.path_to_repo.should == Rails.root.join("tmp", "repositories", "somewhere")
- end
-
it "returns the full web URL for this repo" do
project = Project.new(path: "somewhere")
project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
@@ -269,4 +223,16 @@ describe Project do
it { @project.to_param.should == "gitlab-ci" }
end
end
+
+ describe :repository do
+ let(:project) { create(:project) }
+
+ it "should return valid repo" do
+ project.repository.should be_kind_of(Repository)
+ end
+
+ it "should return nil" do
+ Project.new(path: "empty").repository.should be_nil
+ end
+ end
end
diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb
index 7340ce50ced..0835666a101 100644
--- a/spec/models/protected_branch_spec.rb
+++ b/spec/models/protected_branch_spec.rb
@@ -44,7 +44,7 @@ describe ProtectedBranch do
let(:branch) { create(:protected_branch) }
it 'commits itself to its project' do
- branch.project.should_receive(:commit).with(branch.name)
+ branch.project.repository.should_receive(:commit).with(branch.name)
branch.commit
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
new file mode 100644
index 00000000000..71f9b964e70
--- /dev/null
+++ b/spec/models/repository_spec.rb
@@ -0,0 +1,105 @@
+require "spec_helper"
+
+describe Repository do
+ let(:project) { create(:project) }
+ let(:repository) { project.repository }
+
+ describe "Respond to" do
+ subject { repository }
+
+ it { should respond_to(:repo) }
+ it { should respond_to(:tree) }
+ it { should respond_to(:root_ref) }
+ it { should respond_to(:tags) }
+ it { should respond_to(:commit) }
+ it { should respond_to(:commits) }
+ it { should respond_to(:commits_between) }
+ it { should respond_to(:commits_with_refs) }
+ it { should respond_to(:commits_since) }
+ it { should respond_to(:commits_between) }
+ end
+
+
+ describe "#discover_default_branch" do
+ let(:master) { 'master' }
+ let(:stable) { 'stable' }
+
+ it "returns 'master' when master exists" do
+ repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
+ repository.discover_default_branch.should == 'master'
+ end
+
+ it "returns non-master when master exists but default branch is set to something else" do
+ repository.root_ref = 'stable'
+ repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
+ repository.discover_default_branch.should == 'stable'
+ end
+
+ it "returns a non-master branch when only one exists" do
+ repository.should_receive(:branch_names).at_least(:once).and_return([stable])
+ repository.discover_default_branch.should == 'stable'
+ end
+
+ it "returns nil when no branch exists" do
+ repository.should_receive(:branch_names).at_least(:once).and_return([])
+ repository.discover_default_branch.should be_nil
+ end
+ end
+
+ describe :commit do
+ it "should return first head commit if without params" do
+ repository.commit.id.should == repository.repo.commits.first.id
+ end
+
+ it "should return valid commit" do
+ repository.commit(ValidCommit::ID).should be_valid_commit
+ end
+
+ it "should return nil" do
+ repository.commit("+123_4532530XYZ").should be_nil
+ end
+ end
+
+ describe :tree do
+ before do
+ @commit = repository.commit(ValidCommit::ID)
+ end
+
+ it "should raise error w/o arguments" do
+ lambda { repository.tree }.should raise_error
+ end
+
+ it "should return root tree for commit" do
+ tree = repository.tree(@commit)
+ tree.contents.size.should == ValidCommit::FILES_COUNT
+ tree.contents.map(&:name).should == ValidCommit::FILES
+ end
+
+ it "should return root tree for commit with correct path" do
+ tree = repository.tree(@commit, ValidCommit::C_FILE_PATH)
+ tree.contents.map(&:name).should == ValidCommit::C_FILES
+ end
+
+ it "should return root tree for commit with incorrect path" do
+ repository.tree(@commit, "invalid_path").should be_nil
+ end
+ end
+
+ describe "fresh commits" do
+ it { repository.fresh_commits(3).count.should == 3 }
+ it { repository.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
+ it { repository.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
+ end
+
+ describe "commits_between" do
+ subject do
+ commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
+ "8470d70da67355c9c009e4401746b1d5410af2e3")
+ commits.map { |c| c.id }
+ end
+
+ it { should have(3).elements }
+ it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
+ it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
+ end
+end
diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb
index 7ae483a4003..cc358a2ed3b 100644
--- a/spec/models/system_hook_spec.rb
+++ b/spec/models/system_hook_spec.rb
@@ -56,7 +56,7 @@ describe SystemHook do
user = create(:user)
project = create(:project)
with_resque do
- project.add_access(user, :admin)
+ project.team << [user, :master]
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
@@ -64,7 +64,7 @@ describe SystemHook do
it "project_destroy hook" do
user = create(:user)
project = create(:project)
- project.add_access(user, :admin)
+ project.team << [user, :master]
with_resque do
project.users_projects.clear
end
diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb
new file mode 100644
index 00000000000..65ffe13b490
--- /dev/null
+++ b/spec/models/team_spec.rb
@@ -0,0 +1,18 @@
+require "spec_helper"
+
+describe Team do
+ let(:team) { create(:project).team }
+
+ describe "Respond to" do
+ subject { team }
+
+ it { should respond_to(:developers) }
+ it { should respond_to(:masters) }
+ it { should respond_to(:reporters) }
+ it { should respond_to(:guests) }
+ it { should respond_to(:repository_writers) }
+ it { should respond_to(:repository_masters) }
+ it { should respond_to(:repository_readers) }
+ end
+end
+
diff --git a/spec/models/users_project_spec.rb b/spec/models/users_project_spec.rb
index f85e21ff3f1..e8f5b647ce0 100644
--- a/spec/models/users_project_spec.rb
+++ b/spec/models/users_project_spec.rb
@@ -48,10 +48,10 @@ describe UsersProject do
@user_1 = create :user
@user_2 = create :user
- @project_1.add_access @user_1, :write
- @project_2.add_access @user_2, :read
+ @project_1.team << [ @user_1, :developer ]
+ @project_2.team << [ @user_2, :reporter ]
- @status = UsersProject.import_team(@project_1, @project_2)
+ @status = @project_2.team.import(@project_1)
end
it { @status.should be_true }
@@ -101,8 +101,8 @@ describe UsersProject do
@user_1 = create :user
@user_2 = create :user
- @project_1.add_access @user_1, :write
- @project_2.add_access @user_2, :read
+ @project_1.team << [ @user_1, :developer]
+ @project_2.team << [ @user_2, :reporter]
UsersProject.truncate_teams([@project_1.id, @project_2.id])
end
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index 8f4e51f5a44..781ebab026b 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -6,7 +6,7 @@ describe Gitlab::API do
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
- before { project.add_access(user, :read) }
+ before { project.team << [user, :reporter] }
describe "GET /issues" do
context "when unauthenticated" do
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index f7b067070e0..5da54154a81 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -6,7 +6,7 @@ describe Gitlab::API do
let(:user) { create(:user ) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
- before { project.add_access(user, :read) }
+ before { project.team << [user, :reporters] }
describe "GET /projects/:id/merge_requests" do
context "when unauthenticated" do
diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb
index f7df90d0fdd..80696671462 100644
--- a/spec/requests/api/milestones_spec.rb
+++ b/spec/requests/api/milestones_spec.rb
@@ -7,7 +7,7 @@ describe Gitlab::API do
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:milestone) { create(:milestone, project: project) }
- before { project.add_access(user, :read) }
+ before { project.team << [user, :developer] }
describe "GET /projects/:id/milestones" do
it "should return project milestones" do
diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb
index e783ccf73a5..ae4fc111f63 100644
--- a/spec/requests/api/notes_spec.rb
+++ b/spec/requests/api/notes_spec.rb
@@ -10,7 +10,7 @@ describe Gitlab::API do
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
let!(:wall_note) { create(:note, project: project, author: user) }
- before { project.add_access(user, :read) }
+ before { project.team << [user, :reporter] }
describe "GET /projects/:id/notes" do
context "when unauthenticated" do
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index e829c95e967..c2244210bcf 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -11,7 +11,7 @@ describe Gitlab::API do
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') }
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
- before { project.add_access(user, :read) }
+ before { project.team << [user, :reporter] }
describe "GET /projects" do
context "when unauthenticated" do
@@ -226,14 +226,14 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/commits" do
context "authorized user" do
- before { project.add_access(user2, :read) }
+ before { project.team << [user2, :reporter] }
it "should return project commits" do
get api("/projects/#{project.id}/repository/commits", user)
response.status.should == 200
json_response.should be_an Array
- json_response.first['id'].should == project.commit.id
+ json_response.first['id'].should == project.repository.commit.id
end
end
diff --git a/spec/requests/atom/issues_spec.rb b/spec/requests/atom/issues_spec.rb
index eeb355377c4..0488c1f2266 100644
--- a/spec/requests/atom/issues_spec.rb
+++ b/spec/requests/atom/issues_spec.rb
@@ -6,7 +6,7 @@ describe "Issues Feed" do
let!(:project) { create(:project, namespace: user.namespace) }
let!(:issue) { create(:issue, author: user, project: project) }
- before { project.add_access(user, :read, :write) }
+ before { project.team << [user, :developer] }
context "when authenticated" do
it "should render atom feed" do
diff --git a/spec/requests/gitlab_flavored_markdown_spec.rb b/spec/requests/gitlab_flavored_markdown_spec.rb
index 7f61c6aaa73..78b8c0c513f 100644
--- a/spec/requests/gitlab_flavored_markdown_spec.rb
+++ b/spec/requests/gitlab_flavored_markdown_spec.rb
@@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do
let(:merge_request) { create(:merge_request, project: project) }
let(:fred) do
u = create(:user, name: "fred")
- project.add_access(u, :admin)
+ project.team << [u, :master]
u
end
@@ -33,11 +33,11 @@ describe "Gitlab Flavored Markdown" do
project.repo.gc_auto
end
- let(:commit) { project.commits(@branch_name).first }
+ let(:commit) { project.repository.commits(@branch_name).first }
before do
login_as :user
- project.add_access(@user, :read, :write)
+ project.team << [@user, :developer]
end
describe "for commits" do
diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb
index 0814108523b..2e94ffd0020 100644
--- a/spec/requests/issues_spec.rb
+++ b/spec/requests/issues_spec.rb
@@ -7,8 +7,7 @@ describe "Issues" do
login_as :user
user2 = create(:user)
- project.add_access(@user, :read, :write)
- project.add_access(user2, :read, :write)
+ project.team << [[@user, user2], :developer]
end
describe "Edit issue" do
diff --git a/spec/requests/projects_deploy_keys_spec.rb b/spec/requests/projects_deploy_keys_spec.rb
index 35323f556f9..25b1da9ebd8 100644
--- a/spec/requests/projects_deploy_keys_spec.rb
+++ b/spec/requests/projects_deploy_keys_spec.rb
@@ -5,7 +5,7 @@ describe "Projects", "DeployKeys" do
before do
login_as :user
- project.add_access(@user, :read, :write, :admin)
+ project.team << [@user, :master]
end
describe "GET /keys" do
diff --git a/spec/requests/projects_spec.rb b/spec/requests/projects_spec.rb
index ea87e35ed94..8f613b458c0 100644
--- a/spec/requests/projects_spec.rb
+++ b/spec/requests/projects_spec.rb
@@ -6,7 +6,7 @@ describe "Projects" do
describe "GET /projects/show" do
before do
@project = create(:project, namespace: @user.namespace)
- @project.add_access(@user, :read)
+ @project.team << [@user, :reporter]
visit project_path(@project)
end
@@ -19,7 +19,7 @@ describe "Projects" do
describe "GET /projects/:id/edit" do
before do
@project = create(:project)
- @project.add_access(@user, :admin, :read)
+ @project.team << [@user, :master]
visit edit_project_path(@project)
end
@@ -38,7 +38,7 @@ describe "Projects" do
describe "PUT /projects/:id" do
before do
@project = create(:project, namespace: @user.namespace)
- @project.add_access(@user, :admin, :read)
+ @project.team << [@user, :master]
visit edit_project_path(@project)
@@ -59,7 +59,7 @@ describe "Projects" do
describe "DELETE /projects/:id" do
before do
@project = create(:project, namespace: @user.namespace)
- @project.add_access(@user, :read, :admin)
+ @project.team << [@user, :master]
visit edit_project_path(@project)
end
diff --git a/spec/requests/search_spec.rb b/spec/requests/search_spec.rb
index 17cc0d39946..e338f359f88 100644
--- a/spec/requests/search_spec.rb
+++ b/spec/requests/search_spec.rb
@@ -4,7 +4,7 @@ describe "Search" do
before do
login_as :user
@project = create(:project)
- @project.add_access(@user, :read)
+ @project.team << [@user, :reporter]
visit search_path
fill_in "search", with: @project.name[0..3]
click_button "Search"
diff --git a/spec/requests/security/project_access_spec.rb b/spec/requests/security/project_access_spec.rb
index 060a276b740..a35175102ec 100644
--- a/spec/requests/security/project_access_spec.rb
+++ b/spec/requests/security/project_access_spec.rb
@@ -22,10 +22,10 @@ describe "Application access" do
before do
# full access
- project.users_projects.create(user: master, project_access: UsersProject::MASTER)
+ project.team << [master, :master]
# readonly
- project.users_projects.create(user: reporter, project_access: UsersProject::REPORTER)
+ project.team << [reporter, :reporter]
end
describe "GET /project_code" do
@@ -40,7 +40,7 @@ describe "Application access" do
end
describe "GET /project_code/tree/master" do
- subject { project_tree_path(project, project.root_ref) }
+ subject { project_tree_path(project, project.repository.root_ref) }
it { should be_allowed_for master }
it { should be_allowed_for reporter }
@@ -51,7 +51,7 @@ describe "Application access" do
end
describe "GET /project_code/commits/master" do
- subject { project_commits_path(project, project.root_ref, limit: 1) }
+ subject { project_commits_path(project, project.repository.root_ref, limit: 1) }
it { should be_allowed_for master }
it { should be_allowed_for reporter }
@@ -62,7 +62,7 @@ describe "Application access" do
end
describe "GET /project_code/commit/:sha" do
- subject { project_commit_path(project, project.commit) }
+ subject { project_commit_path(project, project.repository.commit) }
it { should be_allowed_for master }
it { should be_allowed_for reporter }
@@ -107,7 +107,7 @@ describe "Application access" do
describe "GET /project_code/blob" do
before do
- commit = project.commit
+ commit = project.repository.commit
path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob)}.first.name
@blob_path = project_blob_path(project, File.join(commit.id, path))
end
diff --git a/spec/requests/snippets_spec.rb b/spec/requests/snippets_spec.rb
index b231b940a84..770e34dc07c 100644
--- a/spec/requests/snippets_spec.rb
+++ b/spec/requests/snippets_spec.rb
@@ -5,7 +5,7 @@ describe "Snippets" do
before do
login_as :user
- project.add_access(@user, :read, :write)
+ project.team << [@user, :developer]
end
describe "GET /snippets" do
@@ -26,7 +26,7 @@ describe "Snippets" do
before do
# admin access to remove snippet
@user.users_projects.destroy_all
- project.add_access(@user, :read, :write, :admin)
+ project.team << [@user, :master]
visit edit_project_snippet_path(project, @snippet)
end
diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb
index ad88dd77a4f..e6e194d70f5 100644
--- a/spec/support/stubbed_repository.rb
+++ b/spec/support/stubbed_repository.rb
@@ -1,15 +1,14 @@
+require "repository"
+require "project"
+
# Stubs out all Git repository access done by models so that specs can run
# against fake repositories without Grit complaining that they don't exist.
class Project
- def path_to_repo
- if new_record? || path == 'newproject'
- # There are a couple Project specs and features that expect the Project's
- # path to be in the returned path, so let's patronize them.
- Rails.root.join('tmp', 'repositories', path)
+ def repository
+ if path == "empty" || !path
+ nil
else
- # For everything else, just give it the path to one of our real seeded
- # repos.
- Rails.root.join('tmp', 'repositories', 'gitlabhq')
+ GitLabTestRepo.new(path_with_namespace)
end
end
@@ -27,3 +26,9 @@ class Project
end
end
end
+
+class GitLabTestRepo < Repository
+ def repo
+ @repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq'))
+ end
+end