From 53f2130e63b2d20a9c3f6f709f38b70cb27a63ab Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 24 Sep 2014 13:26:53 +0300 Subject: [PATCH 01/11] Use new version of gitlab_git with extended rugged usage --- Gemfile | 4 ++-- Gemfile.lock | 20 +++++++++++++------- lib/gitlab/diff/file.rb | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index cfc205fd866..5c50cb06106 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'omniauth-shibboleth' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 6.0' +gem "gitlab_git", '~> 6.0', git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: 'c405e4cf147fc5f7b9eae8aabaf3bee695eb2832' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' @@ -157,7 +157,7 @@ gem "rack-attack" # Ace editor gem 'ace-rails-ap' -# Keyboard shortcuts +# Keyboard shortcuts gem 'mousetrap-rails' # Semantic UI Sass for Sidebar diff --git a/Gemfile.lock b/Gemfile.lock index bd7ebf3ef44..21a55ad6562 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,15 @@ +GIT + remote: https://gitlab.com/gitlab-org/gitlab_git.git + revision: c405e4cf147fc5f7b9eae8aabaf3bee695eb2832 + ref: c405e4cf147fc5f7b9eae8aabaf3bee695eb2832 + specs: + gitlab_git (6.3.0) + activesupport (~> 4.0) + charlock_holmes (~> 0.6) + gitlab-grit (~> 2.6) + gitlab-linguist (~> 3.0) + rugged (~> 0.21.0) + GEM remote: https://rubygems.org/ specs: @@ -179,12 +191,6 @@ GEM mime-types (~> 1.19) gitlab_emoji (0.0.1.1) emoji (~> 1.0.1) - gitlab_git (6.3.0) - activesupport (~> 4.0) - charlock_holmes (~> 0.6) - gitlab-grit (~> 2.6) - gitlab-linguist (~> 3.0) - rugged (~> 0.21.0) gitlab_meta (7.0) gitlab_omniauth-ldap (1.1.0) net-ldap (~> 0.7.0) @@ -617,7 +623,7 @@ DEPENDENCIES gitlab-grack (~> 2.0.0.pre) gitlab-linguist (~> 3.0.0) gitlab_emoji (~> 0.0.1.1) - gitlab_git (~> 6.0) + gitlab_git (~> 6.0)! gitlab_meta (= 7.0) gitlab_omniauth-ldap (= 1.1.0) gollum-lib (~> 3.0.0) diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 19a1198c68c..4daf65331e8 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -24,7 +24,7 @@ module Gitlab end def raw_diff - diff.diff + diff.diff.to_s end def next_line(index) From 13aec95264541b274d5ed9b828b44860cde93dec Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 24 Sep 2014 15:59:57 +0300 Subject: [PATCH 02/11] Improve diff and bump gitlab_git revision --- Gemfile | 3 ++- Gemfile.lock | 4 ++-- lib/gitlab/diff/parser.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 5c50cb06106..2f221683c63 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,8 @@ gem 'omniauth-shibboleth' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 6.0', git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: 'c405e4cf147fc5f7b9eae8aabaf3bee695eb2832' +# gem "gitlab_git", '~> 6.0', path: '../../gitlab_git' +gem "gitlab_git", '~> 6.0', git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: 'fab781735c1ab2a8f1dc2fda33b169af99ec7e2e' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index 21a55ad6562..b9da7e60a2b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://gitlab.com/gitlab-org/gitlab_git.git - revision: c405e4cf147fc5f7b9eae8aabaf3bee695eb2832 - ref: c405e4cf147fc5f7b9eae8aabaf3bee695eb2832 + revision: fab781735c1ab2a8f1dc2fda33b169af99ec7e2e + ref: fab781735c1ab2a8f1dc2fda33b169af99ec7e2e specs: gitlab_git (6.3.0) activesupport (~> 4.0) diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index 9d6309954a4..447aecb9450 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -13,7 +13,7 @@ module Gitlab lines_arr = ::Gitlab::InlineDiff.processing lines - lines_arr.each do |line| + lines_arr.drop(4).each do |line| raw_line = line.dup next if filename?(line) From 3695ae185b7073f363335d41ba3d6317a63c0739 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 12:19:26 +0300 Subject: [PATCH 03/11] Decorate commit parents Signed-off-by: Dmitriy Zaporozhets --- Gemfile | 2 +- Gemfile.lock | 7 ++++--- app/models/commit.rb | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 2f221683c63..c1d13aa51a9 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ gem 'omniauth-shibboleth' # Extracting information from a git repository # Provide access to Gitlab::Git library # gem "gitlab_git", '~> 6.0', path: '../../gitlab_git' -gem "gitlab_git", '~> 6.0', git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: 'fab781735c1ab2a8f1dc2fda33b169af99ec7e2e' +gem "gitlab_git", '~> 6.0', git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: '97c160e0cbc54d9b5803030e5cc49157440bbe2a' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index b9da7e60a2b..1e5228acaa3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,13 @@ GIT remote: https://gitlab.com/gitlab-org/gitlab_git.git - revision: fab781735c1ab2a8f1dc2fda33b169af99ec7e2e - ref: fab781735c1ab2a8f1dc2fda33b169af99ec7e2e + revision: 97c160e0cbc54d9b5803030e5cc49157440bbe2a + ref: 97c160e0cbc54d9b5803030e5cc49157440bbe2a specs: gitlab_git (6.3.0) activesupport (~> 4.0) charlock_holmes (~> 0.6) - gitlab-grit (~> 2.6) gitlab-linguist (~> 3.0) + rubyzip (~> 1.1) rugged (~> 0.21.0) GEM @@ -446,6 +446,7 @@ GEM ruby-progressbar (1.2.0) rubyntlm (0.1.1) rubypants (0.2.0) + rubyzip (1.1.6) rugged (0.21.0) safe_yaml (0.9.7) sanitize (2.1.0) diff --git a/app/models/commit.rb b/app/models/commit.rb index ff5392957ce..c8b2e0475ff 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -108,4 +108,8 @@ class Commit super end + + def parents + @parents ||= Commit.decorate(super) + end end From b13c1469a317a36a72e87fa92972e440fc8438e5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 12:46:30 +0300 Subject: [PATCH 04/11] Rollback diff drop and set default commit id to HEAD Signed-off-by: Dmitriy Zaporozhets --- app/models/repository.rb | 2 +- lib/gitlab/diff/parser.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 9dd8603621f..5bccc31949b 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -25,7 +25,7 @@ class Repository raw_repository.empty? end - def commit(id = nil) + def commit(id = 'HEAD') return nil unless raw_repository commit = Gitlab::Git::Commit.find(raw_repository, id) commit = Commit.new(commit) if commit diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index 447aecb9450..9d6309954a4 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -13,7 +13,7 @@ module Gitlab lines_arr = ::Gitlab::InlineDiff.processing lines - lines_arr.drop(4).each do |line| + lines_arr.each do |line| raw_line = line.dup next if filename?(line) From 4b65b0e0f5804492e90c3ee8037739c47bcc354b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 13:56:23 +0300 Subject: [PATCH 05/11] Fix wiki Signed-off-by: Dmitriy Zaporozhets --- Gemfile | 4 ++-- Gemfile.lock | 8 ++++---- app/models/project_wiki.rb | 12 ++++++++++++ app/models/wiki_page.rb | 4 ++-- app/views/projects/wikis/history.html.haml | 6 +++--- app/views/projects/wikis/pages.html.haml | 2 +- app/views/projects/wikis/show.html.haml | 2 +- app/views/shared/_file_hljs.html.haml | 13 +++++++------ lib/gitlab/project_search_results.rb | 12 ++++++++---- 9 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index c1d13aa51a9..f4907f4cda2 100644 --- a/Gemfile +++ b/Gemfile @@ -31,8 +31,8 @@ gem 'omniauth-shibboleth' # Extracting information from a git repository # Provide access to Gitlab::Git library -# gem "gitlab_git", '~> 6.0', path: '../../gitlab_git' -gem "gitlab_git", '~> 6.0', git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: '97c160e0cbc54d9b5803030e5cc49157440bbe2a' +# gem "gitlab_git", path: '../../gitlab_git' +gem "gitlab_git", git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: '187ff05aef6fc5390a2d666f35f84de0db9777b7' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index 1e5228acaa3..22e97798d87 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ GIT remote: https://gitlab.com/gitlab-org/gitlab_git.git - revision: 97c160e0cbc54d9b5803030e5cc49157440bbe2a - ref: 97c160e0cbc54d9b5803030e5cc49157440bbe2a + revision: 187ff05aef6fc5390a2d666f35f84de0db9777b7 + ref: 187ff05aef6fc5390a2d666f35f84de0db9777b7 specs: - gitlab_git (6.3.0) + gitlab_git (7.0.0.pre) activesupport (~> 4.0) charlock_holmes (~> 0.6) gitlab-linguist (~> 3.0) @@ -624,7 +624,7 @@ DEPENDENCIES gitlab-grack (~> 2.0.0.pre) gitlab-linguist (~> 3.0.0) gitlab_emoji (~> 0.0.1.1) - gitlab_git (~> 6.0)! + gitlab_git! gitlab_meta (= 7.0) gitlab_omniauth-ldap (= 1.1.0) gollum-lib (~> 3.0.0) diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index a82a300a672..770a26ed894 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -107,6 +107,18 @@ class ProjectWiki [title.gsub(/\.[^.]*$/, ""), title_array.join("/")] end + def search_files(query) + repository.search_files(query, default_branch) + end + + def repository + Repository.new(path_with_namespace, default_branch) + end + + def default_branch + wiki.class.default_ref + end + private def create_repo! diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index b8a0a9eb58b..b9ab6702c53 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -87,14 +87,14 @@ class WikiPage def version return nil unless persisted? - @version ||= Commit.new(Gitlab::Git::Commit.new(@page.version)) + @version ||= @page.version end # Returns an array of Gitlab Commit instances. def versions return [] unless persisted? - @page.versions.map { |v| Commit.new(Gitlab::Git::Commit.new(v)) } + @page.versions end def commit diff --git a/app/views/projects/wikis/history.html.haml b/app/views/projects/wikis/history.html.haml index 7bc566cf7f5..d3a66c48c9b 100644 --- a/app/views/projects/wikis/history.html.haml +++ b/app/views/projects/wikis/history.html.haml @@ -17,11 +17,11 @@ %tr %td = link_to project_wiki_path(@project, @page, version_id: commit.id) do - = commit.short_id + = commit.id[0..10] %td - = commit_author_link(commit, avatar: true, size: 24) + = commit.author.name %td - = commit.title + = commit.message %td #{time_ago_with_tooltip(version.date)} %td diff --git a/app/views/projects/wikis/pages.html.haml b/app/views/projects/wikis/pages.html.haml index 74317faf9d6..264b48ec36c 100644 --- a/app/views/projects/wikis/pages.html.haml +++ b/app/views/projects/wikis/pages.html.haml @@ -8,5 +8,5 @@ = link_to wiki_page.title, project_wiki_path(@project, wiki_page) %small (#{wiki_page.format}) .pull-right - %small Last edited #{time_ago_with_tooltip(wiki_page.commit.created_at)} + %small Last edited #{time_ago_with_tooltip(wiki_page.commit.authored_date)} = paginate @wiki_pages, theme: 'gitlab' diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml index cb923e4ca32..ede4fef9e24 100644 --- a/app/views/projects/wikis/show.html.haml +++ b/app/views/projects/wikis/show.html.haml @@ -17,4 +17,4 @@ %hr .wiki-last-edit-by - Last edited by #{commit_author_link(@page.commit, avatar: true, size: 16)} #{time_ago_with_tooltip(@page.commit.created_at)} + Last edited by #{@page.commit.author.name} #{time_ago_with_tooltip(@page.commit.authored_date)} diff --git a/app/views/shared/_file_hljs.html.haml b/app/views/shared/_file_hljs.html.haml index 7dd97c2b25c..cbc01bd60e0 100644 --- a/app/views/shared/_file_hljs.html.haml +++ b/app/views/shared/_file_hljs.html.haml @@ -1,11 +1,12 @@ %div.highlighted-data{class: user_color_scheme_class} .line-numbers - - blob.data.lines.to_a.size.times do |index| - - offset = defined?(first_line_number) ? first_line_number : 1 - - i = index + offset - = link_to "#L#{i}", id: "L#{i}", rel: "#L#{i}" do - %i.icon-link - = i + - if blob.data.present? + - blob.data.lines.to_a.size.times do |index| + - offset = defined?(first_line_number) ? first_line_number : 1 + - i = index + offset + = link_to "#L#{i}", id: "L#{i}", rel: "#L#{i}" do + %i.icon-link + = i .highlight %pre %code{ class: highlightjs_class(blob.name) } diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 9dc8b34d9c7..e5a04c3d9cf 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -4,7 +4,11 @@ module Gitlab def initialize(project_id, query, repository_ref = nil) @project = Project.find(project_id) - @repository_ref = repository_ref + @repository_ref = if repository_ref.present? + repository_ref + else + nil + end @query = Shellwords.shellescape(query) if query.present? end @@ -50,10 +54,10 @@ module Gitlab def wiki_blobs if project.wiki_enabled? - wiki_repo = Repository.new(ProjectWiki.new(project).path_with_namespace) + project_wiki = ProjectWiki.new(project) - if wiki_repo.exists? - wiki_repo.search_files(query) + unless project_wiki.empty? + project_wiki.search_files(query) else [] end From 424b42d6e9a988c7c0384ac49bf0ca6a344febc1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 15:01:02 +0300 Subject: [PATCH 06/11] Fix 500 error on empty search in project Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/project_search_results.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index e5a04c3d9cf..8b85f3da83f 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -45,7 +45,7 @@ module Gitlab private def blobs - if project.empty_repo? + if project.empty_repo? || query.blank? [] else project.repository.search_files(query, repository_ref) @@ -53,7 +53,7 @@ module Gitlab end def wiki_blobs - if project.wiki_enabled? + if project.wiki_enabled? && query.present? project_wiki = ProjectWiki.new(project) unless project_wiki.empty? From 3a106cbcd3304ec20d936a9f3e2ec18715553d49 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 15:06:41 +0300 Subject: [PATCH 07/11] Fix graphs Signed-off-by: Dmitriy Zaporozhets --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 5bccc31949b..a2bdfe87469 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -137,7 +137,7 @@ class Repository def graph_log Rails.cache.fetch(cache_key(:graph_log)) do - stats = Gitlab::Git::GitStats.new(raw, root_ref, Gitlab.config.git.timeout) + stats = Gitlab::Git::GitStats.new(raw_repository, root_ref, Gitlab.config.git.timeout) stats.parsed_log end end From 619c81b4884ecfc33486007dd5e5324b08c0b0a8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 15:26:35 +0300 Subject: [PATCH 08/11] Fix Commit stats and diff encoding issues Signed-off-by: Dmitriy Zaporozhets --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/controllers/projects/commit_controller.rb | 8 +------- app/controllers/projects/repositories_controller.rb | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index f4907f4cda2..19171e94f46 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ gem 'omniauth-shibboleth' # Extracting information from a git repository # Provide access to Gitlab::Git library # gem "gitlab_git", path: '../../gitlab_git' -gem "gitlab_git", git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: '187ff05aef6fc5390a2d666f35f84de0db9777b7' +gem "gitlab_git", git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: 'b53b948a9248ea3a4b7f2bd6c7f9938fbd5e952b' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index 22e97798d87..eaa9f10105f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://gitlab.com/gitlab-org/gitlab_git.git - revision: 187ff05aef6fc5390a2d666f35f84de0db9777b7 - ref: 187ff05aef6fc5390a2d666f35f84de0db9777b7 + revision: b53b948a9248ea3a4b7f2bd6c7f9938fbd5e952b + ref: b53b948a9248ea3a4b7f2bd6c7f9938fbd5e952b specs: gitlab_git (7.0.0.pre) activesupport (~> 4.0) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index c344297ba8a..34bd682bd90 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -19,13 +19,7 @@ class Projects::CommitController < Projects::ApplicationController [] end - begin - @diffs = @commit.diffs - rescue Grit::Git::GitTimeout - @diffs = [] - @diff_timeout = true - end - + @diffs = @commit.diffs @note = project.build_commit_note(commit) @notes_count = project.notes.for_commit_id(commit.id).count @notes = project.notes.for_commit_id(@commit.id).not_inline.fresh diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb index f30eaadd928..c030320d037 100644 --- a/app/controllers/projects/repositories_controller.rb +++ b/app/controllers/projects/repositories_controller.rb @@ -5,7 +5,7 @@ class Projects::RepositoriesController < Projects::ApplicationController before_filter :require_non_empty_project def stats - @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) + @stats = Gitlab::Git::Stats.new(@repository.raw_repository, @repository.root_ref) @graph = @stats.graph end From 3bf316dbd9b4c555ef9b21f43d56c7d7309766d7 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 16:10:03 +0300 Subject: [PATCH 09/11] Fix security tests Signed-off-by: Dmitriy Zaporozhets --- spec/features/security/project/internal_access_spec.rb | 2 +- spec/features/security/project/private_access_spec.rb | 2 +- spec/features/security/project/public_access_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb index f86b3db32eb..598d554a946 100644 --- a/spec/features/security/project/internal_access_spec.rb +++ b/spec/features/security/project/internal_access_spec.rb @@ -90,7 +90,7 @@ describe "Internal Project Access", feature: true do describe "GET /:project_path/blob" do before do commit = project.repository.commit - path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob) }.first.name + path = '.gitignore' @blob_path = project_blob_path(project, File.join(commit.id, path)) end diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb index a27361f4d15..b1d4c79e05b 100644 --- a/spec/features/security/project/private_access_spec.rb +++ b/spec/features/security/project/private_access_spec.rb @@ -90,7 +90,7 @@ describe "Private Project Access", feature: true do describe "GET /:project_path/blob" do before do commit = project.repository.commit - path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob) }.first.name + path = '.gitignore' @blob_path = project_blob_path(project, File.join(commit.id, path)) end diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb index f114965bd4a..a4c8a2be25a 100644 --- a/spec/features/security/project/public_access_spec.rb +++ b/spec/features/security/project/public_access_spec.rb @@ -95,7 +95,7 @@ describe "Public Project Access", feature: true do describe "GET /:project_path/blob" do before do commit = project.repository.commit - path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob) }.first.name + path = '.gitignore' @blob_path = project_blob_path(project, File.join(commit.id, path)) end From 66ef5c1aa2f50b93ad654dc3b8d9f3a0f5c8bc1b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 16:10:10 +0300 Subject: [PATCH 10/11] Fix satellites Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/satellite/merge_action.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb index 7c9b2294647..e9141f735aa 100644 --- a/lib/gitlab/satellite/merge_action.rb +++ b/lib/gitlab/satellite/merge_action.rb @@ -65,15 +65,16 @@ module Gitlab prepare_satellite!(merge_repo) update_satellite_source_and_target!(merge_repo) if merge_request.for_fork? - # Only show what is new in the source branch compared to the target branch, not the other way around. - # The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2) - # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B" - common_commit = merge_repo.git.native(:merge_base, default_options, ["origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}"]).strip - diffs = merge_repo.diff(common_commit, "source/#{merge_request.source_branch}") + repository = Gitlab::Git::Repository.new(merge_repo.path) + diffs = Gitlab::Git::Diff.between( + repository, + "source/#{merge_request.source_branch}", + "origin/#{merge_request.target_branch}" + ) else raise "Attempt to determine diffs between for a non forked merge request in satellite MergeRequest.id:[#{merge_request.id}]" end - diffs = diffs.map { |diff| Gitlab::Git::Diff.new(diff) } + return diffs end rescue Grit::Git::CommandFailed => ex @@ -97,11 +98,16 @@ module Gitlab prepare_satellite!(merge_repo) update_satellite_source_and_target!(merge_repo) if (merge_request.for_fork?) - commits = merge_repo.commits_between("origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}") + repository = Gitlab::Git::Repository.new(merge_repo.path) + commits = Gitlab::Git::Commit.between( + repository, + "origin/#{merge_request.target_branch}", + "source/#{merge_request.source_branch}" + ) else raise "Attempt to determine commits between for a non forked merge request in satellite MergeRequest.id:[#{merge_request.id}]" end - commits = commits.map { |commit| Gitlab::Git::Commit.new(commit, nil) } + return commits end rescue Grit::Git::CommandFailed => ex From eaeb4a90d431ff5e1e6156c10f3118f70c3c4f8e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 25 Sep 2014 16:22:08 +0300 Subject: [PATCH 11/11] Fix branch API Signed-off-by: Dmitriy Zaporozhets --- lib/api/branches.rb | 4 ++-- spec/models/wiki_page_spec.rb | 2 +- spec/requests/api/branches_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 75783628e3d..14f8b20f6b2 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -14,7 +14,7 @@ module API # Example Request: # GET /projects/:id/repository/branches get ":id/repository/branches" do - present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project + present user_project.repository.branches.sort_by(&:name), with: Entities::RepoObject, project: user_project end # Get a single branch @@ -25,7 +25,7 @@ module API # Example Request: # GET /projects/:id/repository/branches/:branch get ':id/repository/branches/:branch', requirements: { branch: /.*/ } do - @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } + @branch = user_project.repository.branches.find { |item| item.name == params[:branch] } not_found!("Branch does not exist") if @branch.nil? present @branch, with: Entities::RepoObject, project: user_project end diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index cb42822b9bb..d065431ee3a 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -36,7 +36,7 @@ describe WikiPage do end it "sets the version attribute" do - @wiki_page.version.should be_a Commit + @wiki_page.version.should be_a Grit::Commit end end end diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index caded2c9289..8834a6cfa83 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -17,7 +17,7 @@ describe API::API, api: true do get api("/projects/#{project.id}/repository/branches", user) response.status.should == 200 json_response.should be_an Array - json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name + json_response.first['name'].should == project.repository.branch_names.first end end