Documentation
¶
Index ¶
- func GetGitCommonDir() (string, error)
- func GetGitDir() (string, error)
- func GetGitHeadPath() (string, error)
- func GetGitHooksDir() (string, error)
- func GetGitRefsDir() (string, error)
- func GetJujutsuRoot() (string, error)
- func GetMainRepoRoot() (string, error)
- func GetRepoRoot() string
- func IsColocatedJJGit() bool
- func IsJujutsuRepo() bool
- func IsWorktree() bool
- func NormalizePath(path string) string
- func ResetCaches()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGitCommonDir ¶
GetGitCommonDir returns the common git directory shared across all worktrees. For regular repos, this equals GetGitDir(). For worktrees, this returns the main repository's .git directory where shared data (like worktree registrations, hooks, and objects) lives.
Use this instead of GetGitDir() when you need to create new worktrees or access shared git data that should not be scoped to a single worktree. GH#639: This is critical for bare repo setups where GetGitDir() returns a worktree-specific path that cannot host new worktrees.
func GetGitDir ¶
GetGitDir returns the actual .git directory path for the current repository. In a normal repo, this is ".git". In a worktree, .git is a file containing "gitdir: /path/to/actual/git/dir", so we use git rev-parse.
This function uses Git's native worktree-aware APIs and should be used instead of direct filepath.Join(path, ".git") throughout the codebase.
func GetGitHeadPath ¶
GetGitHeadPath returns the path to the Git HEAD file. This function is worktree-aware and handles both regular repos and worktrees.
func GetGitHooksDir ¶
GetGitHooksDir returns the path to the Git hooks directory. This function is worktree-aware: hooks are shared across all worktrees and live in the common git directory (e.g., /repo/.git/hooks), not in the worktree-specific directory (e.g., /repo/.git/worktrees/feature/hooks).
func GetGitRefsDir ¶
GetGitRefsDir returns the path to the Git refs directory. This function is worktree-aware and handles both regular repos and worktrees.
func GetJujutsuRoot ¶
GetJujutsuRoot returns the root directory of the jujutsu repository. Returns empty string and error if not in a jujutsu repository.
Walking stops at a .git boundary: a git repo nested inside a JJ workspace (e.g. a clean-room scratch repo under a JJ-tracked parent) must not inherit the parent's JJ context. Only the directory that contains .git itself is checked for a co-located .jj; we never walk further up.
func GetMainRepoRoot ¶
GetMainRepoRoot returns the main repository root directory. When in a worktree, this returns the main repository root. Otherwise, it returns the regular repository root.
For nested worktrees (worktrees located under the main repo, e.g., /project/.worktrees/feature/), this correctly returns the main repo root (/project/) by using git rev-parse --git-common-dir which always points to the main repo's .git directory. (GH#509) The result is cached after the first call.
func GetRepoRoot ¶
func GetRepoRoot() string
GetRepoRoot returns the root directory of the current git repository. Returns empty string if not in a git repository.
This function is worktree-aware and handles Windows path normalization (Git on Windows may return paths like /c/Users/... or C:/Users/...). It also resolves symlinks to get the canonical path. The result is cached after the first call.
func IsColocatedJJGit ¶
func IsColocatedJJGit() bool
IsColocatedJJGit returns true if this is a colocated jujutsu+git repository. Colocated repos have both .jj and .git directories, created via `jj git init --colocate`. In colocated repos, git hooks work normally since jj manages the git repo.
func IsJujutsuRepo ¶
func IsJujutsuRepo() bool
IsJujutsuRepo returns true if the current directory is in a jujutsu (jj) repository. Jujutsu stores its data in a .jj directory at the repository root.
func IsWorktree ¶
func IsWorktree() bool
IsWorktree returns true if the current directory is in a Git worktree. This is determined by comparing --git-dir and --git-common-dir. The result is cached after the first call since worktree status doesn't change during a single command execution.
func NormalizePath ¶
NormalizePath converts Git's Windows path formats to native format. Git on Windows may return paths like /c/Users/... or C:/Users/... This function converts them to native Windows format (C:\Users\...). On non-Windows systems, this is a no-op.
func ResetCaches ¶
func ResetCaches()
ResetCaches resets all cached git information. This is intended for use by tests that need to change directory between subtests. In production, these caches are safe because the working directory doesn't change during a single command execution.
WARNING: Not thread-safe. Only call from single-threaded test contexts.
Types ¶
This section is empty.