Class: Worktree::Command::Add

Inherits:
Object
  • Object
show all
Defined in:
lib/worktree/command/add.rb

Constant Summary collapse

DEFAULT_BRANCH_REMOTE =
'upstream/master'

Instance Method Summary collapse

Constructor Details

#initialize(branch, from:, project_dir:) ⇒ Add



10
11
12
13
14
15
# File 'lib/worktree/command/add.rb', line 10

def initialize(branch, from:, project_dir:)
  @branch = branch
  @branch_remote = from
  @project_dir = project_dir || Project.resolve(branch).root
  @worktree = "#{@project_dir}/#{@branch}"
end

Instance Method Details

#do!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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
  tmux
end