@@ -47,24 +47,6 @@ WORKTREE_DIR="$REPO_ROOT"
4747_SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
4848: " ${CLAUDE_PLUGIN_ROOT:? CLAUDE_PLUGIN_ROOT must be set} "
4949
50- # --- Count closed tickets using a single awk pass over all .md files ---
51- # Usage: _count_closed_tickets <tickets_dir>
52- # Returns: integer count of .md files whose YAML front-matter contains "status: closed"
53- _count_closed_tickets () {
54- local dir=" $1 "
55- local _result
56- _result=$( find " $dir " -maxdepth 1 -name " *.md" -type f -print0 \
57- | xargs -0 awk '
58- FILENAME != _prev {
59- if (_prev != "" && _found) count++
60- _prev=FILENAME; _found=0; _n=0
61- }
62- /^---$/ { _n++; if(_n==2) nextfile }
63- _n==1 && /^status:[[:space:]]*closed/ { _found=1 }
64- END { if (_prev != "" && _found) count++; print count+0 }
65- ' 2> /dev/null)
66- echo " ${_result:- 0} "
67- }
6850
6951# --- State file helpers (resumable merge support) ---
7052
917899_state_init
918900trap ' _sigurg_handler' URG
919901
902+ # --- Resolve MAIN_REPO early so all phases can use it (including --resume) ---
903+ # MAIN_REPO is the path to the main (non-worktree) checkout. Phases like
904+ # validate and ci_trigger need it, but it was previously set only inside
905+ # _phase_sync — causing unbound variable errors on --resume.
906+ MAIN_REPO=$( dirname " $( git rev-parse --git-common-dir) " )
907+ if [ -z " $MAIN_REPO " ]; then
908+ echo " ERROR: Could not determine main repo path."
909+ exit 1
910+ fi
911+
912+ # PRE_MERGE_SHA: set to current HEAD as a safe default. _phase_merge overwrites
913+ # it with the actual pre-merge SHA before merging. On --resume (merge already
914+ # done), this default is stale but _phase_ci_trigger handles empty/stale values
915+ # gracefully via git diff error suppression (2>/dev/null).
916+ PRE_MERGE_SHA=$( git -C " $MAIN_REPO " rev-parse HEAD 2> /dev/null || echo " " )
917+
920918# =============================================================================
921919# Phase functions — each wraps a sequential phase with state recording
922920# =============================================================================
@@ -1230,38 +1228,10 @@ _phase_push() {
12301228 fi
12311229}
12321230
1233- # --- 4.5) Archive closed tickets if count exceeds threshold ---
1231+ # --- 4.5) Archive phase (no-op — archive-closed- tickets.sh removed in v3 cleanup) ---
12341232_phase_archive () {
12351233 _CURRENT_PHASE=" archive"
12361234 _state_write_phase " archive"
1237-
1238- _ARCHIVE_SCRIPT=" $_SCRIPT_DIR /archive-closed-tickets.sh"
1239- if [ ! -f " $_ARCHIVE_SCRIPT " ]; then
1240- _ARCHIVE_SCRIPT=" $MAIN_REPO /scripts/archive-closed-tickets.sh"
1241- fi
1242- if [ -f " $_ARCHIVE_SCRIPT " ]; then
1243- _CLOSED_COUNT=$( _count_closed_tickets " $TICKETS_DIR " )
1244- if [ " $_CLOSED_COUNT " -gt 100 ]; then
1245- echo " Archiving $_CLOSED_COUNT closed ticket(s)..."
1246- _ARCHIVE_OUT=$( TICKETS_DIR=" $TICKETS_DIR " bash " $_ARCHIVE_SCRIPT " 2>&1 )
1247- echo " $_ARCHIVE_OUT "
1248- # Commit archived tickets if any were moved
1249- if echo " $_ARCHIVE_OUT " | grep -qE ' ^Archived [1-9]' ; then
1250- git add " $TICKETS_DIR " /archive/ 2> /dev/null || true
1251- git add -u " $TICKETS_DIR " / 2> /dev/null || true
1252- if ! git diff --cached --quiet 2> /dev/null; then
1253- git commit -m " chore: archive closed tickets [skip ci]" --quiet
1254- git push --quiet 2>&1 || echo " WARNING: Push of archive commit failed — retry with git push."
1255- echo " OK: Archived tickets committed and pushed."
1256- fi
1257- fi
1258- else
1259- echo " INFO: $_CLOSED_COUNT closed ticket(s) — below threshold (100), skipping archive."
1260- fi
1261- else
1262- echo " INFO: archive-closed-tickets.sh not found — skipping archive step."
1263- fi
1264-
12651235 _state_mark_complete " archive"
12661236}
12671237
0 commit comments