diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 5 | ||||
-rw-r--r-- | app/helpers/gitlab_markdown_helper.rb | 14 | ||||
-rw-r--r-- | app/services/files/create_service.rb | 3 | ||||
-rw-r--r-- | app/services/files/delete_service.rb | 3 | ||||
-rw-r--r-- | app/services/files/update_service.rb | 3 |
6 files changed, 20 insertions, 10 deletions
@@ -29,7 +29,7 @@ gem 'omniauth-github' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", git: 'https://gitlab.com/gitlab-org/gitlab_git.git', ref: '39bc4f043414f1e49f802ed633fa20e6400bfa49' +gem "gitlab_git", git: 'https://gitlab.com/gitlab-org/gitlab_git.git' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.pre', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index 6c876fa1236..fe0fa951632 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,8 +7,7 @@ GIT GIT remote: https://gitlab.com/gitlab-org/gitlab_git.git - revision: 39bc4f043414f1e49f802ed633fa20e6400bfa49 - ref: 39bc4f043414f1e49f802ed633fa20e6400bfa49 + revision: 9e833986399f967e535e6559ac8c3d2c66ae046c specs: gitlab_git (5.1.0.pre) activesupport (~> 4.0.0) @@ -325,7 +324,7 @@ GEM multi_json (~> 1.0) websocket-driver (>= 0.2.0) polyglot (0.3.3) - posix-spawn (0.3.6) + posix-spawn (0.3.8) protected_attributes (1.0.5) activemodel (>= 4.0.1, < 5.0) pry (0.9.12.4) diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 3b9cd67636d..315f1b805b5 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -166,14 +166,14 @@ module GitlabMarkdownHelper def file_exists?(path) return false if path.nil? || path.empty? - return @repository.blob_at(current_ref, path).present? || @repository.tree(:head, path).entries.any? + return @repository.blob_at(current_sha, path).present? || @repository.tree(current_sha, path).entries.any? end # Check if the path is pointing to a directory(tree) or a file(blob) # eg. doc/api is directory and doc/README.md is file def local_path(path) - return "tree" if @repository.tree(:head, path).entries.any? - return "raw" if @repository.blob_at(current_ref, path).image? + return "tree" if @repository.tree(current_sha, path).entries.any? + return "raw" if @repository.blob_at(current_sha, path).image? return "blob" end @@ -181,6 +181,14 @@ module GitlabMarkdownHelper @commit.nil? ? "master" : @commit.id end + def current_sha + if @commit + @commit.id + else + @repository.head_commit.sha + end + end + # We will assume that if no ref exists we can point to master def correct_ref(ref) ref ? ref : "master" diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb index 185ab26d96b..1876dba0887 100644 --- a/app/services/files/create_service.rb +++ b/app/services/files/create_service.rb @@ -24,7 +24,8 @@ module Files return error("Your changes could not be committed, because file name contains not allowed characters") end - blob = repository.blob_at(ref, file_path) + commit = repository.commit(ref) + blob = repository.blob_at(commit.sha, 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 30e512d0912..bacd0ccc5fb 100644 --- a/app/services/files/delete_service.rb +++ b/app/services/files/delete_service.rb @@ -17,7 +17,8 @@ module Files return error("You can only create files if you are on top of a branch") end - blob = repository.blob_at(ref, path) + commit = repository.commit(ref) + blob = repository.blob_at(commit.sha, 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 d59802ae485..19bd62e1e36 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -17,7 +17,8 @@ module Files return error("You can only create files if you are on top of a branch") end - blob = repository.blob_at(ref, path) + commit = repository.commit(ref) + blob = repository.blob_at(commit.sha, path) unless blob return error("You can only edit text files") |