Module: Ace::Git::Atoms::RepositoryChecker
- Defined in:
- lib/ace/git/atoms/repository_checker.rb
Overview
Check repository status: detached HEAD, bare repo, nested worktree Pure function that uses CommandExecutor for git commands
Class Method Summary collapse
-
.bare_repository?(executor: CommandExecutor) ⇒ Boolean
Check if repository is bare.
-
.detached_head?(executor: CommandExecutor) ⇒ Boolean
Check if HEAD is detached.
-
.in_git_repo?(executor: CommandExecutor) ⇒ Boolean
Check if in a git repository.
-
.in_worktree?(executor: CommandExecutor) ⇒ Boolean
Check if current directory is in a git worktree (not main repo).
-
.repository_type(executor: CommandExecutor) ⇒ Symbol
Get repository type description.
-
.status_description(executor: CommandExecutor) ⇒ String
Get human-readable repository status.
-
.usable?(executor: CommandExecutor) ⇒ Boolean
Check if repository is in a usable state for typical git operations.
Class Method Details
.bare_repository?(executor: CommandExecutor) ⇒ Boolean
Check if repository is bare
31 32 33 34 35 36 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 31 def (executor: CommandExecutor) return false unless in_git_repo?(executor: executor) result = executor.execute("git", "rev-parse", "--is-bare-repository") result[:success] && result[:output].strip == "true" end |
.detached_head?(executor: CommandExecutor) ⇒ Boolean
Check if HEAD is detached
20 21 22 23 24 25 26 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 20 def detached_head?(executor: CommandExecutor) return false unless in_git_repo?(executor: executor) result = executor.execute("git", "symbolic-ref", "-q", "HEAD") # If symbolic-ref fails, HEAD is detached !result[:success] end |
.in_git_repo?(executor: CommandExecutor) ⇒ Boolean
Check if in a git repository
13 14 15 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 13 def in_git_repo?(executor: CommandExecutor) executor.in_git_repo? end |
.in_worktree?(executor: CommandExecutor) ⇒ Boolean
Check if current directory is in a git worktree (not main repo)
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 41 def in_worktree?(executor: CommandExecutor) return false unless in_git_repo?(executor: executor) # Get git directory and common directory git_dir = executor.execute("git", "rev-parse", "--git-dir") return false unless git_dir[:success] git_path = git_dir[:output].strip # In worktrees, git-dir contains "worktrees/" git_path.include?("/worktrees/") end |
.repository_type(executor: CommandExecutor) ⇒ Symbol
Get repository type description
57 58 59 60 61 62 63 64 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 57 def repository_type(executor: CommandExecutor) return :not_git unless in_git_repo?(executor: executor) return :bare if (executor: executor) return :worktree if in_worktree?(executor: executor) return :detached if detached_head?(executor: executor) :normal end |
.status_description(executor: CommandExecutor) ⇒ String
Get human-readable repository status
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 69 def status_description(executor: CommandExecutor) case repository_type(executor: executor) when :normal "normal repository" when :detached "detached HEAD state" when :bare "bare repository" when :worktree "git worktree" else "not a git repository" end end |
.usable?(executor: CommandExecutor) ⇒ Boolean
Check if repository is in a usable state for typical git operations
87 88 89 90 91 92 |
# File 'lib/ace/git/atoms/repository_checker.rb', line 87 def usable?(executor: CommandExecutor) return false unless in_git_repo?(executor: executor) return false if (executor: executor) true end |