Class: AgentC::Configs::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_c/configs/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir:, initial_revision:, working_subdir: "", worktrees_root_dir:, worktree_branch_prefix:, worktree_envs:, logger:) ⇒ Repo

Returns a new instance of Repo.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/agent_c/configs/repo.rb', line 15

def initialize(
  dir:,
  initial_revision:,
  working_subdir: "",
  worktrees_root_dir:,
  worktree_branch_prefix:,
  worktree_envs:,
  logger:
)
  @dir = dir
  @initial_revision = initial_revision
  @working_subdir = working_subdir
  @worktrees_root_dir = worktrees_root_dir
  @worktree_branch_prefix = worktree_branch_prefix
  @worktree_envs = worktree_envs
  @logger = logger
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/agent_c/configs/repo.rb', line 6

def dir
  @dir
end

#initial_revisionObject (readonly)

Returns the value of attribute initial_revision.



6
7
8
# File 'lib/agent_c/configs/repo.rb', line 6

def initial_revision
  @initial_revision
end

#working_subdirObject (readonly)

Returns the value of attribute working_subdir.



6
7
8
# File 'lib/agent_c/configs/repo.rb', line 6

def working_subdir
  @working_subdir
end

#worktree_branch_prefixObject (readonly)

Returns the value of attribute worktree_branch_prefix.



6
7
8
# File 'lib/agent_c/configs/repo.rb', line 6

def worktree_branch_prefix
  @worktree_branch_prefix
end

#worktree_envsObject (readonly)

Returns the value of attribute worktree_envs.



6
7
8
# File 'lib/agent_c/configs/repo.rb', line 6

def worktree_envs
  @worktree_envs
end

#worktrees_root_dirObject (readonly)

Returns the value of attribute worktrees_root_dir.



6
7
8
# File 'lib/agent_c/configs/repo.rb', line 6

def worktrees_root_dir
  @worktrees_root_dir
end

Instance Method Details

#workspaces(store) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/agent_c/configs/repo.rb', line 33

def workspaces(store)
  git = Utils::Git.new(dir)
  logger.info("Checking worktrees")

  worktree_configs.map { |spec|
    worktree_dir = spec.fetch(:dir)

    if store.workspace.where(dir: spec.fetch(:workspace_dir)).exists?
      logger.info("worktree record exists at #{worktree_dir}, not creating/resetting worktree")
    else
      logger.info("creating/resetting worktree at: #{worktree_dir}")
      git.create_worktree(
        dir: worktree_dir,
        branch: spec.fetch(:branch),
        revision: initial_revision,
      )
    end

    store
      .workspace
      .ensure_created!(
        dir: spec.fetch(:workspace_dir),
        env: spec.fetch(:env)
      )
  }.tap { logger.info("done checking worktrees")}
end