class Worktree::Command::Add
Constants
- DEFAULT_BRANCH_REMOTE
Public Class Methods
new(branch, from:, project_dir:)
click to toggle source
# File lib/worktree/command/add.rb, line 10 def initialize(branch, from:, project_dir:) @branch = branch @branch_remote = from @project_dir = File.expand_path project_dir || Project.resolve(branch).root @worktree = "#{@project_dir}/#{@branch}" end
Public Instance Methods
do!()
click to toggle source
# File lib/worktree/command/add.rb, line 17 def do! raise "Worktree #{@worktree} already exists!" if Dir.exist?(@worktree) raise 'No master repo found!' unless Dir.exist?("#{@project_dir}/master/.git") # fetch all # TODO: silence log while fetching remotes git.remotes.each { |remote| git.fetch(remote, prune: true) } # update master git.pull('upstream', 'master') Worktree.run_command "git worktree add -b #{@branch} ../#{@branch} #{@branch_remote}", chdir: "#{@project_dir}/master" copy_files clone_dbs Launcher.new( project_dir: @project_dir, branch: @branch ).launch! end
Private Instance Methods
clone_dbs()
click to toggle source
# File lib/worktree/command/add.rb, line 47 def clone_dbs if File.exist?("#{@project_dir}/#{@branch}/config/database.yml") Feature::CloneDbs.new( project_dir: @project_dir, branch: @branch ).run! unless TTY::Prompt.new.no?('Clone development database?') end end
copy_files()
click to toggle source
# File lib/worktree/command/add.rb, line 40 def copy_files Feature::CopyFiles.new( project_dir: @project_dir, branch: @branch ).run! end
git()
click to toggle source
# File lib/worktree/command/add.rb, line 56 def git @git ||= Worktree.git_for(@project_dir) end