2.2 KiB
2.2 KiB
Step 02: Git Gateway
Prerequisites: none.
Read README.md and 00-legacy-analysis.md first.
Goal
Extend GitService into a complete, tested gateway for all git operations the watcher and builder need.
Design
Keep the existing approach: shell out to the git CLI via ProcessBuilder.
Extract a small GitCommandRunner (command + workingDir → exit code, stdout, stderr) so GitService becomes testable and readable.
Operations to add (legacy references in parentheses):
fetchOrigin()andfetchBranch(branch)with authentication (legacygit_with_gitea_token, askpass). Use theGIT_ASKPASSenvironment technique: write a temp script returninggit.account/git.tokenfrom config;GIT_TERMINAL_PROMPT=0. Only needed for HTTPS origins; skip auth setup for SSH origins.localBranches(),originBranches()(legacybranch_candidates).hasNewCommits(branch)— compare local head with upstream/origin (legacybranch_has_new_commits,has_new_commitsviarev-list).newOriginBranches(maxAge)— origin branches without local counterpart whose latest commit is younger thanwatcher.newBranchMaxAge(legacyrecent_new_origin_branches).checkout(branch)— switch, or create tracking branch from origin (legacyswitch_to_branch).resetHardToOrigin(branch)(legacypull_branch_if_possible).commitTimestamp(sha),currentBranch(),headCommit().
Parse the newBranchMaxAge duration format (5d, 12h) in a small dedicated parser with tests.
Out of Scope
- No polling loop (step 06), no build triggering.
- No Gitea API calls (step 03); only the askpass credential bridge is set up here.
Tests
GitCommandRunnerunit tests.- Integration tests against local fixture repositories: create a bare "origin" repo and a clone in a temp dir via the runner itself, then exercise fetch/branch/commit operations. No network access needed.
- Duration parser edge cases.
- Askpass script content test (do not test against a real remote).
Acceptance Criteria
./gradlew ktlintFormatthen./gradlew buildis green.- No temp askpass files leak (created per invocation or cleaned via try/finally; legacy leaked them).