Class: GDK::Project::GitWorktree

Inherits:
Object
  • Object
show all
Defined in:
lib/gdk/project/git_worktree.rb

Constant Summary collapse

DEFAULT_RETRY_ATTEMPTS =
3

Instance Method Summary collapse

Constructor Details

#initialize(worktree_path, default_branch, revision, auto_rebase: false) ⇒ GitWorktree

Returns a new instance of GitWorktree.



8
9
10
11
12
13
# File 'lib/gdk/project/git_worktree.rb', line 8

def initialize(worktree_path, default_branch, revision, auto_rebase: false)
  @worktree_path = worktree_path
  @default_branch = default_branch
  @revision = revision
  @auto_rebase = auto_rebase
end

Instance Method Details

#updateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gdk/project/git_worktree.rb', line 15

def update
  stashed = stash_save

  sh = execute_command(fetch_cmd)
  unless sh.success?
    GDK::Output.puts(sh.read_stderr, stderr: true)
    GDK::Output.error("Failed to fetch for '#{short_worktree_path}'", sh.read_stderr)
    return false
  end

  result = auto_rebase? ? execute_rebase : execute_checkout_and_pull
ensure
  stashed ? stash_pop : result
end