Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a4633537
Commit
a4633537
authored
Sep 04, 2012
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add "empty_repo?" method to Repository role
Replaces two calls that this method simplifies
parent
7e76610d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
6 deletions
+32
-6
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-1
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-1
app/roles/repository.rb
app/roles/repository.rb
+8
-4
spec/roles/repository_spec.rb
spec/roles/repository_spec.rb
+22
-0
No files found.
app/controllers/application_controller.rb
View file @
a4633537
...
@@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base
...
@@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base
end
end
def
require_non_empty_project
def
require_non_empty_project
redirect_to
@project
unless
@project
.
repo_exists?
&&
@project
.
has_commits
?
redirect_to
@project
if
@project
.
empty_repo
?
end
end
def
no_cache_headers
def
no_cache_headers
...
...
app/controllers/projects_controller.rb
View file @
a4633537
...
@@ -50,7 +50,7 @@ class ProjectsController < ApplicationController
...
@@ -50,7 +50,7 @@ class ProjectsController < ApplicationController
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
if
@project
.
repo_exists?
&&
@project
.
has_commits
?
unless
@project
.
empty_repo
?
@last_push
=
current_user
.
recent_push
(
@project
.
id
)
@last_push
=
current_user
.
recent_push
(
@project
.
id
)
render
:show
render
:show
else
else
...
...
app/roles/repository.rb
View file @
a4633537
...
@@ -8,6 +8,10 @@ module Repository
...
@@ -8,6 +8,10 @@ module Repository
false
false
end
end
def
empty_repo?
!
repo_exists?
||
!
has_commits?
end
def
commit
(
commit_id
=
nil
)
def
commit
(
commit_id
=
nil
)
Commit
.
find_or_first
(
repo
,
commit_id
,
root_ref
)
Commit
.
find_or_first
(
repo
,
commit_id
,
root_ref
)
end
end
...
@@ -38,7 +42,7 @@ module Repository
...
@@ -38,7 +42,7 @@ module Repository
def
has_post_receive_file?
def
has_post_receive_file?
hook_file
=
File
.
join
(
path_to_repo
,
'hooks'
,
'post-receive'
)
hook_file
=
File
.
join
(
path_to_repo
,
'hooks'
,
'post-receive'
)
File
.
exists?
(
hook_file
)
File
.
exists?
(
hook_file
)
end
end
def
tags
def
tags
...
@@ -67,7 +71,7 @@ module Repository
...
@@ -67,7 +71,7 @@ module Repository
def
repo_exists?
def
repo_exists?
@repo_exists
||=
(
repo
&&
!
repo
.
branches
.
empty?
)
@repo_exists
||=
(
repo
&&
!
repo
.
branches
.
empty?
)
rescue
rescue
@repo_exists
=
false
@repo_exists
=
false
end
end
...
@@ -94,7 +98,7 @@ module Repository
...
@@ -94,7 +98,7 @@ module Repository
!!
commit
!!
commit
end
end
def
root_ref
def
root_ref
default_branch
||
"master"
default_branch
||
"master"
end
end
...
@@ -104,7 +108,7 @@ module Repository
...
@@ -104,7 +108,7 @@ module Repository
# Archive Project to .tar.gz
# 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
# app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz
#
#
def
archive_repo
ref
def
archive_repo
ref
...
...
spec/roles/repository_spec.rb
0 → 100644
View file @
a4633537
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment