Commit 654bf11

Eric Bower  ·  2026-05-11 23:59:25 -0400 EDT
parent b18d1a6
chore: detect force push
2 files changed,  +11, -2
M hooks/post-receive
+10, -2
 1@@ -45,8 +45,16 @@ while read -r old_sha new_sha ref; do
 2   # Workspace points to the tar on pgs.sh
 3   workspace="${PGS_HOST}:${tar_path}"
 4 
 5-  event=$(printf '{"type":"git.push","name":"%s","workspace":"%s","branch":"%s","commit":"%s","artifact_dest":"%s:%s"}' \
 6-    "$repo" "$workspace" "$branch" "$new_sha" "$PGS_HOST" "$pgs_path")
 7+  # Detect force push: old SHA is not an ancestor of new SHA
 8+  is_force_push=false
 9+  if [ "$old_sha" != "0000000000000000000000000000000000000000" ]; then
10+    if ! git merge-base --is-ancestor "$old_sha" "$new_sha" 2>/dev/null; then
11+      is_force_push=true
12+    fi
13+  fi
14+
15+  event=$(printf '{"type":"git.push","name":"%s","workspace":"%s","branch":"%s","commit":"%s","artifact_dest":"%s:%s","force_push":%s}' \
16+    "$repo" "$workspace" "$branch" "$new_sha" "$PGS_HOST" "$pgs_path" "$is_force_push")
17 
18   log "publish: $event"
19   echo "$event" | ssh -T "$PIPE_HOST" pub -b=false build.event
M main.go
+1, -0
1@@ -69,6 +69,7 @@ type Event struct {
2 	Branch       string `json:"branch"`
3 	Commit       string `json:"commit"`
4 	ArtifactDest string `json:"artifact_dest"`
5+	ForcePush    bool   `json:"force_push,omitempty"`
6 }
7 
8 func NewCfg() (*Cfg, string, bool) {