Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/repository.rb10
-rw-r--r--app/services/files/create_service.rb3
-rw-r--r--app/services/files/delete_service.rb3
-rw-r--r--app/services/files/update_service.rb3
4 files changed, 13 insertions, 6 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 271c2e4dbbc..a408fe13f80 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -178,4 +178,14 @@ class Repository
Tree.new(self, sha, path)
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
diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb
index 1876dba0887..1998fb79e7d 100644
--- a/app/services/files/create_service.rb
+++ b/app/services/files/create_service.rb
@@ -24,8 +24,7 @@ module Files
return error("Your changes could not be committed, because file name contains not allowed characters")
end
- commit = repository.commit(ref)
- blob = repository.blob_at(commit.sha, file_path)
+ blob = repository.blob_at_branch(ref, file_path)
if blob
return error("Your changes could not be committed, because file with such name exists")
diff --git a/app/services/files/delete_service.rb b/app/services/files/delete_service.rb
index bacd0ccc5fb..ff5dc6ef34c 100644
--- a/app/services/files/delete_service.rb
+++ b/app/services/files/delete_service.rb
@@ -17,8 +17,7 @@ module Files
return error("You can only create files if you are on top of a branch")
end
- commit = repository.commit(ref)
- blob = repository.blob_at(commit.sha, path)
+ blob = repository.blob_at_branch(ref, path)
unless blob
return error("You can only edit text files")
diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb
index 19bd62e1e36..c631f28749c 100644
--- a/app/services/files/update_service.rb
+++ b/app/services/files/update_service.rb
@@ -17,8 +17,7 @@ module Files
return error("You can only create files if you are on top of a branch")
end
- commit = repository.commit(ref)
- blob = repository.blob_at(commit.sha, path)
+ blob = repository.blob_at_branch(ref, path)
unless blob
return error("You can only edit text files")