Skip to content

Support running from any subdirectory of a git repo#12

Merged
ryanmoran merged 1 commit intomainfrom
directory-jump
Mar 17, 2026
Merged

Support running from any subdirectory of a git repo#12
ryanmoran merged 1 commit intomainfrom
directory-jump

Conversation

@ryanmoran
Copy link
Owner

What

Allow contagent to be invoked from any subdirectory within a git repository, not just the root. Previously, running from a subdirectory would fail because the git server validation looked for .git in the current directory rather than walking up to the repo root.

Key changes:

  • Extract FindRoot as a public function in the git package, using git rev-parse --show-toplevel to locate the repo root
  • main.go calls FindRoot upfront, then passes the resolved root to both NewServer and CreateArchive
  • When running from a subdirectory, the container's working directory is set to config.WorkingDir + relPath so the container starts at the equivalent location — keeping the git root path stable in the container
  • Remove the .git existence check from NewServer (validation now happens via FindRoot in the caller)
  • Update tests to reflect the deferred error model (archive errors surface at read time, not construction time)

Why

Working in monorepos was difficult because contagent required being at the repo root. Users had to cd to the root before every invocation, breaking workflows where tools are run from within a package or service subdirectory.

How to Test

Prerequisites:

  • Build the binary: go build -o contagent .
  • A git repo with at least one subdirectory and a committed file in it

Steps:

  1. Clone or use an existing multi-directory git repo
  2. cd into a subdirectory (e.g., cd src/)
  3. Run contagent from there: /path/to/contagent <your-command>
  4. Verify the container starts and the working directory inside the container reflects the subdirectory (e.g., /app/src)
  5. Verify the full repo is available at /app inside the container
  6. For comparison, run from the repo root and confirm it still works as before

Run the test suite:

go test ./...

@ryanmoran ryanmoran merged commit 3bcdd8a into main Mar 17, 2026
1 check passed
@ryanmoran ryanmoran deleted the directory-jump branch March 17, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant