From c1ff89fa2adc4809ea093833464f41ea9af5bc6f Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 4 Sep 2012 11:30:49 -0400 Subject: [PATCH 1/5] Rename projects.js to projects.js.coffee --- app/assets/javascripts/{projects.js => projects.js.coffee} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/assets/javascripts/{projects.js => projects.js.coffee} (100%) diff --git a/app/assets/javascripts/projects.js b/app/assets/javascripts/projects.js.coffee similarity index 100% rename from app/assets/javascripts/projects.js rename to app/assets/javascripts/projects.js.coffee -- GitLab From 7e76610d0a521af73459ffc2ba7b3956ab9da34c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 4 Sep 2012 11:36:14 -0400 Subject: [PATCH 2/5] Update the projects js file to coffeescript; refactor the clone panel switcher --- app/assets/javascripts/projects.js.coffee | 40 ++++++++++------------- app/views/projects/empty.html.haml | 13 -------- app/views/projects/show.html.haml | 5 --- app/views/refs/_head.html.haml | 5 --- 4 files changed, 18 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/projects.js.coffee b/app/assets/javascripts/projects.js.coffee index 6bbfbacc382..ca8f13f6744 100644 --- a/app/assets/javascripts/projects.js.coffee +++ b/app/assets/javascripts/projects.js.coffee @@ -1,25 +1,21 @@ -function Projects() { - $("#project_name").live("change", function(){ - var slug = slugify($(this).val()); - $("#project_code").val(slug); - $("#project_path").val(slug); - }); +window.Projects = -> + $("#project_name").live "change", -> + slug = slugify($(this).val()) + $("#project_code").val(slug) + $("#project_path").val(slug) - $('.new_project, .edit_project').live('ajax:before', function() { - $('.project_new_holder, .project_edit_holder').hide(); - $('.save-project-loader').show(); - }); + $(".new_project, .edit_project").live "ajax:before", -> + $(".project_new_holder, .project_edit_holder").hide() + $(".save-project-loader").show() - $('form #project_default_branch').chosen(); + $("form #project_default_branch").chosen() + disableButtonIfEmtpyField "#project_name", ".project-submit" - disableButtonIfEmtpyField("#project_name", ".project-submit") -} - -function initGitCloneSwitcher() { - var link_sel = ".project_clone_holder button"; - $(link_sel).bind("click", function(e) { - $(link_sel).removeClass("active"); - $(this).addClass("active"); - $("#project_clone").val($(this).attr("data-clone")); - }) -} +# Git clone panel switcher +$ -> + scope = $('.project_clone_holder') + if scope.length > 0 + $('a, button', scope).click -> + $('a, button', scope).removeClass('active') + $(this).addClass('active') + $('#project_clone', scope).val($(this).data('clone')) diff --git a/app/views/projects/empty.html.haml b/app/views/projects/empty.html.haml index d408c0a64ae..6ec7015a82e 100644 --- a/app/views/projects/empty.html.haml +++ b/app/views/projects/empty.html.haml @@ -36,16 +36,3 @@ - if can? current_user, :admin_project, @project .prepend-top-20 = link_to 'Remove project', @project, confirm: 'Are you sure?', method: :delete, class: "btn danger right" - - - -:javascript - $(function(){ - var link_sel = ".project_clone_holder a"; - $(link_sel).bind("click", function() { - $(link_sel).removeClass("active"); - $(this).addClass("active"); - $("#project_clone").val($(this).attr("data-clone")); - }) - }) - diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index de3e9cefc06..21459da256f 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -2,8 +2,3 @@ = render 'clone_panel' = render "events/event_last_push", event: @last_push .content_list= render @events - -:javascript - $(function(){ - initGitCloneSwitcher(); - }) diff --git a/app/views/refs/_head.html.haml b/app/views/refs/_head.html.haml index affd07cba38..d51602de9b7 100644 --- a/app/views/refs/_head.html.haml +++ b/app/views/refs/_head.html.haml @@ -12,8 +12,3 @@ %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH %button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" - -:javascript - $(function(){ - initGitCloneSwitcher(); - }) -- GitLab From a4633537737d1ea85c74b2089fa1c82e407c0cfa Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 4 Sep 2012 11:37:38 -0400 Subject: [PATCH 3/5] Add "empty_repo?" method to Repository role Replaces two calls that this method simplifies --- app/controllers/application_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/roles/repository.rb | 12 ++++++++---- spec/roles/repository_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 spec/roles/repository_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9aab250dbd4..d53b23bb246 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base end def require_non_empty_project - redirect_to @project unless @project.repo_exists? && @project.has_commits? + redirect_to @project if @project.empty_repo? end def no_cache_headers diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bd7f811e59f..170b8892936 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -50,7 +50,7 @@ class ProjectsController < ApplicationController respond_to do |format| format.html do - if @project.repo_exists? && @project.has_commits? + unless @project.empty_repo? @last_push = current_user.recent_push(@project.id) render :show else diff --git a/app/roles/repository.rb b/app/roles/repository.rb index 5fa950db6d6..5f6c35414e1 100644 --- a/app/roles/repository.rb +++ b/app/roles/repository.rb @@ -8,6 +8,10 @@ module Repository false end + def empty_repo? + !repo_exists? || !has_commits? + end + def commit(commit_id = nil) Commit.find_or_first(repo, commit_id, root_ref) end @@ -38,7 +42,7 @@ module Repository def has_post_receive_file? hook_file = File.join(path_to_repo, 'hooks', 'post-receive') - File.exists?(hook_file) + File.exists?(hook_file) end def tags @@ -67,7 +71,7 @@ module Repository def repo_exists? @repo_exists ||= (repo && !repo.branches.empty?) - rescue + rescue @repo_exists = false end @@ -94,7 +98,7 @@ module Repository !!commit end - def root_ref + def root_ref default_branch || "master" end @@ -104,7 +108,7 @@ module Repository # Archive Project to .tar.gz # - # Already packed repo archives stored at + # Already packed repo archives stored at # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz # def archive_repo ref diff --git a/spec/roles/repository_spec.rb b/spec/roles/repository_spec.rb new file mode 100644 index 00000000000..62aecc1341f --- /dev/null +++ b/spec/roles/repository_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Project, "Repository" do + let(:project) { build(: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 +end -- GitLab From 82a399688316caa9d860d93204f5bfc9b7847a16 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 4 Sep 2012 12:03:40 -0400 Subject: [PATCH 4/5] Remove projects/_show partial I have no earthly idea what this file was for, but I couldn't find it being rendered anywhere. --- app/views/projects/_show.html.haml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 app/views/projects/_show.html.haml diff --git a/app/views/projects/_show.html.haml b/app/views/projects/_show.html.haml deleted file mode 100644 index e8a5b00dd0e..00000000000 --- a/app/views/projects/_show.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -%h5.title - = @project.name -%br -%div - %a.btn.info{href: tree_project_ref_path(@project, @project.root_ref)} Browse code -   - %a.btn{href: project_commits_path(@project)} Commits - %strong.right - = link_to project_path(@project) do - Switch to project → -%br -.alert-message.block-message.warning - .input - .input-prepend - %span.add-on git clone - = text_field_tag :project_clone, @project.url_to_repo, class: "xlarge one_click_select git_clone_url" - -= simple_format @project.description -- unless @events.blank? - %h4.middle_title Recent Activity - .content_list= render @events - - -- GitLab From 0bc4ecfedd1f8580ab861955b0c21605e5a3aadb Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 4 Sep 2012 12:05:08 -0400 Subject: [PATCH 5/5] Change projects/empty to include the clone_panel partial instead of duplicating --- app/views/projects/_clone_panel.html.haml | 22 +++++++++++----------- app/views/projects/empty.html.haml | 10 ++-------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/views/projects/_clone_panel.html.haml b/app/views/projects/_clone_panel.html.haml index 76059f32237..20891610ace 100644 --- a/app/views/projects/_clone_panel.html.haml +++ b/app/views/projects/_clone_panel.html.haml @@ -8,14 +8,14 @@ = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" .span4.right .right - - if can? current_user, :download_code, @project - = link_to archive_project_repository_path(@project), class: "btn small grouped" do - %i.icon-download-alt - Download - - if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project) - = link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn small grouped" do - Merge Request - - if @project.issues_enabled && can?(current_user, :write_issue, @project) - = link_to new_project_issue_path(@project), title: "New Issue", class: "btn small grouped" do - Issue - + - unless @project.empty_repo? + - if can? current_user, :download_code, @project + = link_to archive_project_repository_path(@project), class: "btn small grouped" do + %i.icon-download-alt + Download + - if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project) + = link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn small grouped" do + Merge Request + - if @project.issues_enabled && can?(current_user, :write_issue, @project) + = link_to new_project_issue_path(@project), title: "New Issue", class: "btn small grouped" do + Issue diff --git a/app/views/projects/empty.html.haml b/app/views/projects/empty.html.haml index 6ec7015a82e..d9a151fc706 100644 --- a/app/views/projects/empty.html.haml +++ b/app/views/projects/empty.html.haml @@ -1,12 +1,6 @@ = render 'shared/no_ssh' -.project_clone_panel - .row - .span7 - .form-horizontal - .input-prepend.project_clone_holder - = link_to "SSH", "#", class: "btn small active", :"data-clone" => @project.ssh_url_to_repo - = link_to "HTTP", "#", class: "btn small", :"data-clone" => @project.http_url_to_repo - = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" += render 'clone_panel' + %div.git-empty %h4 Git global setup: %pre.dark -- GitLab