cli-jaw 2.17.22 → 2.17.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,38 +75,49 @@ prepare_promotion_checkout() {
75
75
  local preview_sha="$2"
76
76
  local promotion_branch="$3"
77
77
  local checkout_dir="$4"
78
- local branch_probe_status
78
+ local branch_probe_status remote_branch_sha
79
79
  promotion_checkout_path_safe "$checkout_dir" || return 1
80
80
  if [ ! -d "$checkout_dir" ] || [ -n "$(find "$checkout_dir" -mindepth 1 -maxdepth 1 -print -quit)" ]; then
81
81
  promotion_error "promotion checkout directory must exist and be empty: $checkout_dir"
82
82
  return 1
83
83
  fi
84
84
 
85
- if git ls-remote --exit-code "$remote_url" "refs/heads/$promotion_branch" >/dev/null 2>&1; then
85
+ # A pre-existing remote branch is only a hazard when it points somewhere the
86
+ # promotion did not certify. Since #480 the promotion extends `preview`
87
+ # itself, so the branch is EXPECTED to exist and to be exactly the certified
88
+ # head — rejecting that unconditionally made the ff promotion unable to run at
89
+ # all. What still has to fail is a branch that resolves to any other commit:
90
+ # that is either leftover state from an aborted run or a head that moved while
91
+ # the gates ran, and building on it would publish an uncertified tree.
92
+ remote_branch_sha="$(git ls-remote "$remote_url" "refs/heads/$promotion_branch" 2>/dev/null | awk 'NR==1{print $1}')"
93
+ branch_probe_status=$?
94
+ if [ "$branch_probe_status" -ne 0 ]; then
95
+ promotion_error "could not verify remote promotion branch state: $promotion_branch"
96
+ return 1
97
+ fi
98
+ if [ -n "$remote_branch_sha" ] && [ "$remote_branch_sha" != "$preview_sha" ]; then
86
99
  promotion_error "remote promotion branch already exists: $promotion_branch"
87
100
  return 1
88
- else
89
- branch_probe_status=$?
90
- if [ "$branch_probe_status" -ne 2 ]; then
91
- promotion_error "could not verify remote promotion branch state: $promotion_branch"
92
- return "$branch_probe_status"
93
- fi
94
101
  fi
95
102
 
96
103
  git clone --quiet --no-recurse-submodules --no-checkout "$remote_url" "$checkout_dir"
97
- git -C "$checkout_dir" checkout --quiet -b "$promotion_branch" "$preview_sha"
104
+ # -B rather than -b: the clone already carries `preview` as a local branch, so
105
+ # -b would abort on a name the promotion is supposed to be standing on. The
106
+ # start point is the certified SHA either way, and the check below proves HEAD
107
+ # landed there.
108
+ git -C "$checkout_dir" checkout --quiet -B "$promotion_branch" "$preview_sha"
98
109
  assert_promotion_checkout_initial "$checkout_dir" "$preview_sha"
99
110
  }
100
111
 
101
112
  assert_promotion_checkout_ready_to_push() {
102
113
  local checkout_dir="$1"
103
114
  local preview_sha="$2"
104
- local promotion_branch="$3"
115
+ local target_branch="$3"
105
116
  local current_branch checkout_status commit_count
106
117
  promotion_checkout_path_safe "$checkout_dir" || return 1
107
118
  current_branch="$(git -C "$checkout_dir" branch --show-current)"
108
- if [ "$current_branch" != "$promotion_branch" ]; then
109
- promotion_error "promotion checkout branch is $current_branch, expected $promotion_branch"
119
+ if [ "$current_branch" != "$target_branch" ]; then
120
+ promotion_error "promotion checkout branch is $current_branch, expected $target_branch"
110
121
  return 1
111
122
  fi
112
123
  if ! git -C "$checkout_dir" merge-base --is-ancestor "$preview_sha" HEAD; then
@@ -128,52 +139,3 @@ assert_promotion_checkout_ready_to_push() {
128
139
  return 1
129
140
  fi
130
141
  }
131
-
132
- # ─── Post-promotion realignment (#466) ─────────────────────────────────────
133
- #
134
- # A squash promotion folds preview's commits into one NEW commit on main, so
135
- # main stops being an ancestor of preview the moment the promotion succeeds —
136
- # and promote-to-main.sh demands exactly that ancestry on the next cycle. The
137
- # script breaks its own precondition every release. Leaving the repair to prose
138
- # is what produced the 2.17.13 incident: a hand-made merge claimed to take the
139
- # preview tree, took main's, and shipped a tarball missing #418's code.
140
- #
141
- # Built from plumbing (commit-tree) rather than a worktree on purpose: the tree
142
- # is an INPUT here, not a merge result, so the published content cannot change
143
- # no matter which side is which. The caller re-checks it anyway.
144
- realign_branch_onto_main() {
145
- local branch="$1" main_sha="$2" message="$3"
146
- local head tree new_commit
147
- head="$(git ls-remote origin "refs/heads/$branch" | cut -f1)"
148
- if [ -z "$head" ]; then
149
- echo "realign: no origin/$branch to realign" >&2
150
- return 0
151
- fi
152
- if git merge-base --is-ancestor "$main_sha" "$head" 2>/dev/null; then
153
- echo "realign: $branch already has main as an ancestor"
154
- return 0
155
- fi
156
- git fetch origin "$branch" >/dev/null 2>&1 || true
157
- tree="$(git rev-parse "$head^{tree}")" || {
158
- promotion_error "realign: cannot read $branch tree"
159
- return 1
160
- }
161
- new_commit="$(git commit-tree "$tree" -p "$head" -p "$main_sha" -m "$message")" || {
162
- promotion_error "realign: could not create the realignment commit for $branch"
163
- return 1
164
- }
165
- if [ "$(git rev-parse "$new_commit^{tree}")" != "$tree" ]; then
166
- promotion_error "realign: $branch tree changed; refusing to push"
167
- return 1
168
- fi
169
- if ! git merge-base --is-ancestor "$main_sha" "$new_commit"; then
170
- promotion_error "realign: $main_sha is still not an ancestor of $branch; refusing to push"
171
- return 1
172
- fi
173
- if git push origin "$new_commit:refs/heads/$branch" >/dev/null 2>&1; then
174
- echo "realign: $branch now has main as an ancestor, tree unchanged"
175
- else
176
- echo "realign: could not push $branch (did it move?)" >&2
177
- return 1
178
- fi
179
- }