Commit graph

4 commits

Author SHA1 Message Date
a7e72c4c05
gitinterface: resolve worktrees for detached git dirs and worktrees
Worktree resolution chopped ".git" off the resolved GIT_DIR path, which
only works for the standard <repo>/.git layout. This breaks repositories
created with --separate-git-dir, misclassifies linked worktrees as bare
(so file restoration was silently skipped), and misclassifies bare
repositories named foo.git as non-bare. Linked worktrees could not even
be loaded because ensureNoCompatObjectFormat expects a config file that
only exists in the repository's common Git directory.

- add Repository.GetWorktree() resolving via $GIT_DIR/gitdir,
  core.worktree, load-time discovery, then the standard layout;
  validated so stale or malformed records fall through cleanly
- determine bareness via rev-parse --is-bare-repository instead of the
  GIT_DIR name, exposed through the ErrNoWorktree sentinel
- read configuration from the common directory via $GIT_DIR/commondir
- route Status(), RestoreWorktree(), and post-propagation restore
  through GetWorktree()

Fixes #1006

Signed-off-by: lakshit verma <vermalucky2004@gmail.com>
2026-08-24 16:16:00 +05:30
Andrew Nesbitt
12ab1b37ac
pkg/gitinterface: remove os.Chdir; set cmd.Dir on the executor instead
LoadRepository did os.Chdir(repositoryPath) to run 'git rev-parse
--git-dir', and Status/RestoreWorktree/tree-restore did the same to run
worktree-relative commands. os.Chdir is process-global; concurrent
LoadRepository calls for different paths could each resolve the wrong
gitDirPath.

Adds executor.withDir(dir) which sets cmd.Dir. LoadRepository now runs
'git rev-parse --absolute-git-dir' with cmd.Dir set to the repository
path (and EvalSymlinks the result to match prior behaviour). The
worktree commands use withDir(worktree).

TestLoadRepositoryConcurrent runs 20 pairs of LoadRepository for two
distinct repos in parallel under -race and asserts each gets its own
gitDirPath.

Signed-off-by: Andrew Nesbitt <andrewnez@gmail.com>
2026-06-29 17:13:31 +01:00
Pat Zielinski
1f8cf912cc
pkg: Drop support for Git versions older than v2.38.0
Signed-off-by: Pat Zielinski <git@patzielinski.com>
2026-06-10 09:56:56 -04:00
Pat Zielinski
f649b141d3
pkg: Move gitinterface to pkg
Signed-off-by: Pat Zielinski <git@patzielinski.com>
2026-01-16 14:03:36 -05:00
Renamed from internal/gitinterface/utils.go (Browse further)