Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions config/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ create_worktree() {
# Create destination directory if it doesn't exist
mkdir -p "$(dirname "$WORKTREE_PATH")"

WORKTREE_BASE_SHA=$(git -C /workspace rev-parse HEAD 2>/dev/null || echo "")

# Add worktree (idempotent: if branch already exists, reuses it)
if git -C /workspace worktree add "$WORKTREE_PATH" -b "$WORKTREE_BRANCH" 2>/dev/null; then
echo "[entrypoint] Worktree created on new branch: ${WORKTREE_BRANCH}"
Expand Down Expand Up @@ -124,8 +126,10 @@ run_agent() {

# Collect post-run metrics
local commit_count last_commit finished_at end_epoch duration_secs
commit_count=$(git -C "$WORKTREE_PATH" rev-list --count HEAD 2>/dev/null || echo 0)
last_commit=$(git -C "$WORKTREE_PATH" log --oneline -1 2>/dev/null || echo "none")
commit_count=$(git -C "$WORKTREE_PATH" -c "safe.directory=$WORKTREE_PATH" \
rev-list --count "${WORKTREE_BASE_SHA:-HEAD}..HEAD" 2>/dev/null || echo 0)
last_commit=$(git -C "$WORKTREE_PATH" -c "safe.directory=$WORKTREE_PATH" \
log --oneline -1 2>/dev/null || echo "none")
finished_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
end_epoch=$(date +%s)
duration_secs=$((end_epoch - start_epoch))
Expand Down
17 changes: 16 additions & 1 deletion config/spec/entrypoint_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ git() {
[[ "$GIT_WORKTREE_NEW_BRANCH_SUCCEEDS" == "true" ]] && return 0 || return 1
elif [[ "$*" == *"worktree add"* ]]; then
[[ "$GIT_WORKTREE_EXISTING_BRANCH_SUCCEEDS" == "true" ]] && return 0 || return 1
elif [[ "$*" == *"rev-parse HEAD"* ]]; then
echo "basef00d"
return 0
elif [[ "$*" == *"rev-list --count"* ]]; then
echo "3"
return 0
Expand Down Expand Up @@ -486,7 +489,19 @@ WRAPPER_EOF

It "collects commit count after agent finishes"
When run run_entrypoint --worktree agent-br --task "do work"
The output should include "[MOCK] git -C /worktrees/agent-br rev-list --count HEAD"
The output should include "rev-list --count"
The status should equal 0
End

It "uses safe.directory flag when collecting git metrics"
When run run_entrypoint --worktree agent-br --task "do work"
The output should include "safe.directory=/worktrees/agent-br"
The status should equal 0
End

It "counts only agent commits using BASE..HEAD"
When run run_entrypoint --worktree agent-br --task "do work"
The output should include "basef00d..HEAD"
The status should equal 0
End
End
Expand Down
Loading