diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-02-14 18:18:05 +0200 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-02-24 11:43:20 +0200 |
commit | 71a844cdaee129d4e300c20cbb27db009cf81b73 (patch) | |
tree | dfd520e826c08f2ff8e2938bf995922d0de511f6 /lib | |
parent | 7561b1c2a486ae57e9fbebadadbe1269bfdba6a0 (diff) | |
download | gitlab-ce-71a844cdaee129d4e300c20cbb27db009cf81b73.tar.gz |
Web Editor: save to new branch
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/satellite/files/edit_file_action.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/satellite/files/new_file_action.rb | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/gitlab/satellite/files/edit_file_action.rb b/lib/gitlab/satellite/files/edit_file_action.rb index 82d71ab9906..3cb9c0b5ecb 100644 --- a/lib/gitlab/satellite/files/edit_file_action.rb +++ b/lib/gitlab/satellite/files/edit_file_action.rb @@ -10,7 +10,7 @@ module Gitlab # Returns false if committing the change fails # Returns false if pushing from the satellite to bare repo failed or was rejected # Returns true otherwise - def commit!(content, commit_message, encoding) + def commit!(content, commit_message, encoding, new_branch = nil) in_locked_and_timed_satellite do |repo| prepare_satellite!(repo) @@ -42,10 +42,12 @@ module Gitlab end + target_branch = new_branch.present? ? "#{ref}:#{new_branch}" : ref + # push commit back to bare repo # will raise CommandFailed when push fails begin - repo.git.push({ raise: true, timeout: true }, :origin, ref) + repo.git.push({ raise: true, timeout: true }, :origin, target_branch) rescue Grit::Git::CommandFailed => ex log_and_raise(PushFailed, ex.message) end diff --git a/lib/gitlab/satellite/files/new_file_action.rb b/lib/gitlab/satellite/files/new_file_action.rb index 69f7ffa94e4..724dfa0d042 100644 --- a/lib/gitlab/satellite/files/new_file_action.rb +++ b/lib/gitlab/satellite/files/new_file_action.rb @@ -9,7 +9,7 @@ module Gitlab # Returns false if committing the change fails # Returns false if pushing from the satellite to bare repo failed or was rejected # Returns true otherwise - def commit!(content, commit_message, encoding) + def commit!(content, commit_message, encoding, new_branch = nil) in_locked_and_timed_satellite do |repo| prepare_satellite!(repo) @@ -45,9 +45,15 @@ module Gitlab # will raise CommandFailed when commit fails repo.git.commit(raise: true, timeout: true, a: true, m: commit_message) + target_branch = if new_branch.present? && !@project.empty_repo? + "#{ref}:#{new_branch}" + else + "#{current_ref}:#{ref}" + end + # push commit back to bare repo # will raise CommandFailed when push fails - repo.git.push({ raise: true, timeout: true }, :origin, "#{current_ref}:#{ref}") + repo.git.push({ raise: true, timeout: true }, :origin, target_branch) # everything worked true |