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 | |
| 45 | 45 | # Workspace points to the tar on pgs.sh | |
| 46 | 46 | workspace="${PGS_HOST}:${tar_path}" | |
| 47 | 47 | ||
| 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") | |
| 50 | 58 | ||
| 51 | 59 | log "publish: $event" | |
| 52 | 60 | echo "$event" | ssh -T "$PIPE_HOST" pub -b=false build.event |
M
main.go
+1,
-0