Commit 55572c4e86c6b4cb12c8984b54de57fc02972ad1

Authored by Dmitriy Zaporozhets
1 parent d701d586

Repository#blob_at_branch

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/models/repository.rb
@@ -178,4 +178,14 @@ class Repository @@ -178,4 +178,14 @@ class Repository
178 178
179 Tree.new(self, sha, path) 179 Tree.new(self, sha, path)
180 end 180 end
  181 +
  182 + def blob_at_branch(branch_name, path)
  183 + last_commit = commit(branch_name)
  184 +
  185 + if last_commit
  186 + blob_at(last_commit.sha, path)
  187 + else
  188 + nil
  189 + end
  190 + end
181 end 191 end
app/services/files/create_service.rb
@@ -24,8 +24,7 @@ module Files @@ -24,8 +24,7 @@ module Files
24 return error("Your changes could not be committed, because file name contains not allowed characters") 24 return error("Your changes could not be committed, because file name contains not allowed characters")
25 end 25 end
26 26
27 - commit = repository.commit(ref)  
28 - blob = repository.blob_at(commit.sha, file_path) 27 + blob = repository.blob_at_branch(ref, file_path)
29 28
30 if blob 29 if blob
31 return error("Your changes could not be committed, because file with such name exists") 30 return error("Your changes could not be committed, because file with such name exists")
app/services/files/delete_service.rb
@@ -17,8 +17,7 @@ module Files @@ -17,8 +17,7 @@ module Files
17 return error("You can only create files if you are on top of a branch") 17 return error("You can only create files if you are on top of a branch")
18 end 18 end
19 19
20 - commit = repository.commit(ref)  
21 - blob = repository.blob_at(commit.sha, path) 20 + blob = repository.blob_at_branch(ref, path)
22 21
23 unless blob 22 unless blob
24 return error("You can only edit text files") 23 return error("You can only edit text files")
app/services/files/update_service.rb
@@ -17,8 +17,7 @@ module Files @@ -17,8 +17,7 @@ module Files
17 return error("You can only create files if you are on top of a branch") 17 return error("You can only create files if you are on top of a branch")
18 end 18 end
19 19
20 - commit = repository.commit(ref)  
21 - blob = repository.blob_at(commit.sha, path) 20 + blob = repository.blob_at_branch(ref, path)
22 21
23 unless blob 22 unless blob
24 return error("You can only edit text files") 23 return error("You can only edit text files")