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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
2b592f29
Commit
2b592f29
authored
Feb 05, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'minor_refactoring' into 'master'
Minor refactoring Add Repository#blob_at_branch method
parents
d701d586
55572c4e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
6 deletions
+13
-6
app/models/repository.rb
app/models/repository.rb
+10
-0
app/services/files/create_service.rb
app/services/files/create_service.rb
+1
-2
app/services/files/delete_service.rb
app/services/files/delete_service.rb
+1
-2
app/services/files/update_service.rb
app/services/files/update_service.rb
+1
-2
No files found.
app/models/repository.rb
View file @
2b592f29
...
@@ -178,4 +178,14 @@ class Repository
...
@@ -178,4 +178,14 @@ class Repository
Tree
.
new
(
self
,
sha
,
path
)
Tree
.
new
(
self
,
sha
,
path
)
end
end
def
blob_at_branch
(
branch_name
,
path
)
last_commit
=
commit
(
branch_name
)
if
last_commit
blob_at
(
last_commit
.
sha
,
path
)
else
nil
end
end
end
end
app/services/files/create_service.rb
View file @
2b592f29
...
@@ -24,8 +24,7 @@ module Files
...
@@ -24,8 +24,7 @@ module Files
return
error
(
"Your changes could not be committed, because file name contains not allowed characters"
)
return
error
(
"Your changes could not be committed, because file name contains not allowed characters"
)
end
end
commit
=
repository
.
commit
(
ref
)
blob
=
repository
.
blob_at_branch
(
ref
,
file_path
)
blob
=
repository
.
blob_at
(
commit
.
sha
,
file_path
)
if
blob
if
blob
return
error
(
"Your changes could not be committed, because file with such name exists"
)
return
error
(
"Your changes could not be committed, because file with such name exists"
)
...
...
app/services/files/delete_service.rb
View file @
2b592f29
...
@@ -17,8 +17,7 @@ module Files
...
@@ -17,8 +17,7 @@ module Files
return
error
(
"You can only create files if you are on top of a branch"
)
return
error
(
"You can only create files if you are on top of a branch"
)
end
end
commit
=
repository
.
commit
(
ref
)
blob
=
repository
.
blob_at_branch
(
ref
,
path
)
blob
=
repository
.
blob_at
(
commit
.
sha
,
path
)
unless
blob
unless
blob
return
error
(
"You can only edit text files"
)
return
error
(
"You can only edit text files"
)
...
...
app/services/files/update_service.rb
View file @
2b592f29
...
@@ -17,8 +17,7 @@ module Files
...
@@ -17,8 +17,7 @@ module Files
return
error
(
"You can only create files if you are on top of a branch"
)
return
error
(
"You can only create files if you are on top of a branch"
)
end
end
commit
=
repository
.
commit
(
ref
)
blob
=
repository
.
blob_at_branch
(
ref
,
path
)
blob
=
repository
.
blob_at
(
commit
.
sha
,
path
)
unless
blob
unless
blob
return
error
(
"You can only edit text files"
)
return
error
(
"You can only edit text files"
)
...
...
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