diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-11-10 14:00:55 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-11-10 14:00:55 +0000 |
commit | 9c9e88da56246c6efcd6a52a14f360e9a71a63e6 (patch) | |
tree | cbf89daef9331109e9e0361c0466637b73de9705 /app | |
parent | 2a829885e2e7aecfdd2ac55fff5d1ff08a25ef0f (diff) | |
parent | 6cbd3cafd3c3e7e318f84483460ba5c6af3fc4cf (diff) | |
download | gitlab-ce-9c9e88da56246c6efcd6a52a14f360e9a71a63e6.tar.gz |
Merge branch 'fix/error-when-invalid-branch-for-new-pipeline-used' into 'master'
Fix error when using invalid branch name when creating a new pipeline
## What does this MR do?
This MR fixes `500` error when creating a new pipeline though user interface ("Run pipeline")
## Are there points in the code the reviewer needs to double check?
Is this a good approach to catch those exceptions on `Repository` level?
## Does this MR meet the acceptance criteria?
- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- Tests
- [x] Added for this feature/bug
## What are the relevant issue numbers?
Closes #23982
See merge request !7324
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/pipelines_controller.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 371cc3787fb..533af80aee0 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -18,7 +18,9 @@ class Projects::PipelinesController < Projects::ApplicationController end def create - @pipeline = Ci::CreatePipelineService.new(project, current_user, create_params).execute(ignore_skip_ci: true, save_on_errors: false) + @pipeline = Ci::CreatePipelineService + .new(project, current_user, create_params) + .execute(ignore_skip_ci: true, save_on_errors: false) unless @pipeline.persisted? render 'new' return diff --git a/app/models/repository.rb b/app/models/repository.rb index 7d06ce1e85b..fe991904601 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -84,15 +84,17 @@ class Repository def commit(ref = 'HEAD') return nil unless exists? + commit = if ref.is_a?(Gitlab::Git::Commit) ref else Gitlab::Git::Commit.find(raw_repository, ref) end + commit = ::Commit.new(commit, @project) if commit commit - rescue Rugged::OdbError + rescue Rugged::OdbError, Rugged::TreeError nil end @@ -232,6 +234,8 @@ class Repository def ref_exists?(ref) rugged.references.exist?(ref) + rescue Rugged::ReferenceError + false end def update_ref!(name, newrev, oldrev) @@ -270,11 +274,7 @@ class Repository end def kept_around?(sha) - begin - ref_exists?(keep_around_ref_name(sha)) - rescue Rugged::ReferenceError - false - end + ref_exists?(keep_around_ref_name(sha)) end def tag_names |