Add --force flag to reverse sync
Bypasses the PR step and force-pushes the subrepo's state directly onto the monorepo branch. Also skips the skip-dirty guard. Only valid with --reverse. Returns status "forced". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
10
lib/auth.sh
10
lib/auth.sh
@@ -28,6 +28,16 @@ subrepo_auth_url() {
|
||||
fi
|
||||
}
|
||||
|
||||
# ─── Monorepo Auth URL ─────────────────────────────────────────────
|
||||
# Derives a push-capable HTTPS URL from MONOREPO_API.
|
||||
# MONOREPO_API shape: https://<host>/api/v1/repos/<org/repo>
|
||||
|
||||
mono_auth_url() {
|
||||
local api_host_path
|
||||
api_host_path=$(echo "$MONOREPO_API" | sed 's|https://||; s|/api/v1/repos/|/|')
|
||||
echo "https://${BOT_USER}:${GITEA_TOKEN}@${api_host_path}.git"
|
||||
}
|
||||
|
||||
# ─── Remote Queries ─────────────────────────────────────────────────
|
||||
|
||||
subrepo_ls_remote() {
|
||||
|
||||
53
lib/sync.sh
53
lib/sync.sh
@@ -240,6 +240,8 @@ reverse_sync() {
|
||||
|
||||
log "INFO" "=== Reverse sync: subrepo/${subrepo_branch} → mono/${mono_branch} ==="
|
||||
|
||||
local force_mode="${SYNC_REVERSE_FORCE:-0}"
|
||||
|
||||
# 1. Clone subrepo
|
||||
git clone "$(subrepo_auth_url)" \
|
||||
--branch "$subrepo_branch" --single-branch \
|
||||
@@ -286,9 +288,13 @@ reverse_sync() {
|
||||
fi
|
||||
|
||||
if [ -z "$human_commits" ]; then
|
||||
log "INFO" "No new human commits in subrepo — nothing to sync"
|
||||
echo "skip-dirty"
|
||||
return
|
||||
if [ "$force_mode" = "1" ]; then
|
||||
log "WARN" "No human commits found — force mode: continuing anyway"
|
||||
else
|
||||
log "INFO" "No new human commits in subrepo — nothing to sync"
|
||||
echo "skip-dirty"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
log "INFO" "New human commits to sync:"
|
||||
@@ -400,16 +406,28 @@ reverse_sync() {
|
||||
|
||||
log "INFO" "Pushed to staging branch via josh: ${staging_branch}${linearized:+ (linearized)}"
|
||||
|
||||
# 6. Create PR on monorepo (NEVER direct push)
|
||||
local pr_body
|
||||
local linearize_note=""
|
||||
if [ "$linearized" = true ]; then
|
||||
linearize_note="
|
||||
# 6. Publish: force-push directly (--force) or create PR (default)
|
||||
if [ "$force_mode" = "1" ]; then
|
||||
log "WARN" "Force mode: pushing ${staging_branch} directly to mono/${mono_branch} — bypassing PR"
|
||||
local mono_dir="${work_dir}/monorepo"
|
||||
git clone "$(mono_auth_url)" \
|
||||
--branch "$staging_branch" --single-branch \
|
||||
"$mono_dir" || die "Failed to clone monorepo staging branch for force-push"
|
||||
git -C "$mono_dir" push --force "$(mono_auth_url)" \
|
||||
"HEAD:refs/heads/${mono_branch}" \
|
||||
|| die "Failed to force-push to mono/${mono_branch}"
|
||||
log "INFO" "Force-pushed mono/${staging_branch} → mono/${mono_branch}"
|
||||
echo "forced"
|
||||
else
|
||||
local pr_body
|
||||
local linearize_note=""
|
||||
if [ "$linearized" = true ]; then
|
||||
linearize_note="
|
||||
> **Note:** Merge commits were squashed during sync because the subrepo
|
||||
> history contained merges that josh-proxy cannot map (see ADR-011).
|
||||
> Regular commits are preserved individually."
|
||||
fi
|
||||
pr_body="## Subrepo changes
|
||||
fi
|
||||
pr_body="## Subrepo changes
|
||||
|
||||
New commits from subrepo \`${subrepo_branch}\`:
|
||||
|
||||
@@ -422,14 +440,15 @@ ${linearize_note}
|
||||
- [ ] No leaked credentials or environment-specific config
|
||||
- [ ] CI passes"
|
||||
|
||||
create_pr "${MONOREPO_API}" "${GITEA_TOKEN}" \
|
||||
"$mono_branch" "$staging_branch" \
|
||||
"[Subrepo Sync] ${subrepo_branch} → ${mono_branch}" \
|
||||
"$pr_body" \
|
||||
|| die "Failed to create PR on monorepo (check GITEA_TOKEN)"
|
||||
create_pr "${MONOREPO_API}" "${GITEA_TOKEN}" \
|
||||
"$mono_branch" "$staging_branch" \
|
||||
"[Subrepo Sync] ${subrepo_branch} → ${mono_branch}" \
|
||||
"$pr_body" \
|
||||
|| die "Failed to create PR on monorepo (check GITEA_TOKEN)"
|
||||
|
||||
log "INFO" "Reverse sync PR created on monorepo"
|
||||
echo "pr-created"
|
||||
log "INFO" "Reverse sync PR created on monorepo"
|
||||
echo "pr-created"
|
||||
fi
|
||||
}
|
||||
|
||||
# ─── Initial Import: Subrepo → Monorepo (first time) ───────────────
|
||||
|
||||
Reference in New Issue
Block a user