lib/socialcast-git-extensions/git.rb in socialcast-git-extensions-3.1.15 vs lib/socialcast-git-extensions/git.rb in socialcast-git-extensions-3.1.17
- old
+ new
@@ -7,10 +7,17 @@
private
def assert_not_protected_branch!(branch, action)
raise "Cannot #{action} reserved branch" if reserved_branch?(branch)
end
+ def assert_in_last_known_good_staging(branch)
+ branches_in_last_known_staging = branches(:remote => true, :merged => last_known_good_staging_branch)
+ unless branches_in_last_known_staging.include? branch
+ raise "Cannot release #{branch} unless it has already been promoted separately to #{staging_branch} and the build has passed."
+ end
+ end
+
# lookup the current branch of the PWD
def current_branch
repo = Grit::Repo.new(Dir.pwd)
Grit::Head.current(repo).name
end
@@ -26,10 +33,31 @@
# @returns empty [String] when no github.user is set on the system
def current_user
`git config -z --global --get github.user`.strip
end
+ def backport_to(branch, shas)
+ run_cmd "git checkout #{base_branch}"
+ run_cmd "git checkout -b #{branch}"
+ begin
+ run_cmd "git cherry-pick #{shas.join(' ')}"
+ rescue
+ while true
+ proceed = $terminal.ask "Error during cherry-pick. You can proceed by resolving the conflicts and using 'git cherry-pick --continue' to finish the cherry-pick in another terminal. Would you like to proceed (y/n)?"
+ if proceed.to_s.downcase == 'n'
+ run_cmd "git cherry-pick --abort"
+ exit 1
+ elsif proceed.to_s.downcase == 'y'
+ break
+ else
+ say "Invalid response"
+ end
+ end
+ end
+ run_cmd "git push origin HEAD"
+ end
+
# retrieve a list of branches
def branches(options = {})
branches = []
args = []
args << '-r' if options[:remote]
@@ -181,9 +209,13 @@
ENV['BASE_BRANCH'] || config['base_branch'] || Socialcast::Gitx::DEFAULT_BASE_BRANCH
end
def staging_branch
config['staging_branch'] || Socialcast::Gitx::DEFAULT_STAGING_BRANCH
+ end
+
+ def last_known_good_staging_branch
+ config['last_known_good_staging_branch'] || Socialcast::Gitx::DEFAULT_LAST_KNOWN_GOOD_STAGING_BRANCH
end
def prototype_branch
config['prototype_branch'] || Socialcast::Gitx::DEFAULT_PROTOTYPE_BRANCH
end