Class: Worktree::Command::CherryPick
- Inherits:
-
Object
- Object
- Worktree::Command::CherryPick
- Defined in:
- lib/worktree/command/cherry_pick.rb
Instance Method Summary collapse
- #do! ⇒ Object
-
#initialize(commit, to:, project_dir:, launcher_vars: {}, clone_db: false) ⇒ CherryPick
constructor
A new instance of CherryPick.
Constructor Details
#initialize(commit, to:, project_dir:, launcher_vars: {}, clone_db: false) ⇒ CherryPick
Returns a new instance of CherryPick.
6 7 8 9 10 11 12 13 |
# File 'lib/worktree/command/cherry_pick.rb', line 6 def initialize(commit, to:, project_dir:, launcher_vars: {}, clone_db: false) @commit = commit[0..7] # short commit @to = to @branch = "cherry-pick-#{@commit}-to-#{@to.tr('/', '-')}" @project_dir = File. project_dir @clone_db = clone_db @launcher_vars = launcher_vars end |
Instance Method Details
#do! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/worktree/command/cherry_pick.rb', line 15 def do! # fetch all remotes git.remotes.each { |remote| git.fetch(remote, prune: true) } # create new git worktree Worktree.run_command "git worktree add -b #{@branch} ../#{@branch} #{@to}", chdir: git.dir # cherry-pick specified commit into specified branch begin Worktree.run_command "git cherry-pick #{@commit} -m 1", chdir: "#{@project_dir}/#{@branch}" rescue Worktree::Error => e # bypass conflicts while cherry-picking Worktree.logger.warn { e. } end # copy files specified in configuration into new folder Feature::CopyFiles.new(project_dir: @project_dir, branch: @branch).run! # clone PG database Feature::CloneDbs.new(project_dir: @project_dir, branch: @branch).run! if @clone_db # launch in editor Launcher.new(project_dir: @project_dir, branch: @branch, extra_vars: @launcher_vars).launch! end |