Commit 654bf11

Eric Bower  ·  2026-05-11 23:59:25 -0400 EDT
parent b18d1a6
chore: detect force push
2 files changed,  +11, -2
+10, -2
......@@ -45,8 +45,16 @@ while read -r old_sha new_sha ref; do
4545 # Workspace points to the tar on pgs.sh
4646 workspace="${PGS_HOST}:${tar_path}"
4747
48- event=$(printf '{"type":"git.push","name":"%s","workspace":"%s","branch":"%s","commit":"%s","artifact_dest":"%s:%s"}' \
49- "$repo" "$workspace" "$branch" "$new_sha" "$PGS_HOST" "$pgs_path")
48+ # Detect force push: old SHA is not an ancestor of new SHA
49+ is_force_push=false
50+ if [ "$old_sha" != "0000000000000000000000000000000000000000" ]; then
51+ if ! git merge-base --is-ancestor "$old_sha" "$new_sha" 2>/dev/null; then
52+ is_force_push=true
53+ fi
54+ fi
55+
56+ event=$(printf '{"type":"git.push","name":"%s","workspace":"%s","branch":"%s","commit":"%s","artifact_dest":"%s:%s","force_push":%s}' \
57+ "$repo" "$workspace" "$branch" "$new_sha" "$PGS_HOST" "$pgs_path" "$is_force_push")
5058
5159 log "publish: $event"
5260 echo "$event" | ssh -T "$PIPE_HOST" pub -b=false build.event
+1, -0
......@@ -69,6 +69,7 @@ type Event struct {
6969 Branch string `json:"branch"`
7070 Commit string `json:"commit"`
7171 ArtifactDest string `json:"artifact_dest"`
72+ ForcePush bool `json:"force_push,omitempty"`
7273 }
7374
7475 func NewCfg() (*Cfg, string, bool) {