diff options
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r-- | app/helpers/tree_helper.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 563450159b5..692971f4627 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -75,11 +75,27 @@ module TreeHelper if user_access(project).can_push_to_branch?(ref) ref else - project = tree_edit_project(project) - project.repository.next_branch('patch') + patch_branch_name(ref) end end + # Generate a patch branch name that should look like: + # `username-branchname-patch-epoch` + # where `epoch` is the last 5 digits of the time since epoch (in + # milliseconds) + # + # Note: this correlates with how the WebIDE formats the branch name + # and if this implementation changes, so should the `placeholderBranchName` + # definition in app/assets/javascripts/ide/stores/modules/commit/getters.js + def patch_branch_name(ref) + return unless current_user + + username = current_user.username + epoch = time_in_milliseconds.to_s.last(5) + + "#{username}-#{ref}-patch-#{epoch}" + end + def tree_edit_project(project = @project) if can?(current_user, :push_code, project) project |