From b9b42e3174d39176dfb5e3863dd06384f88f1ae9 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 16 Aug 2026 10:13:39 +0800 Subject: [PATCH] ci: make canary --- Makefile | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index e3acfaa3..3bcc4f05 100644 --- a/Makefile +++ b/Makefile @@ -110,30 +110,40 @@ dev: fi -# Merge local feat into canary, push canary, then restore the previous branch. -# Does not leave the working tree on canary when started from another branch. +# Merge the current local branch into canary, push canary, then restore it. +# Dirty worktrees are auto-stashed and restored after the operation. canary: @set -e; \ if ! git rev-parse --git-dir >/dev/null 2>&1; then \ echo "Error: not a git repository"; exit 1; \ fi; \ - if [ -n "$$(git status --porcelain)" ]; then \ - echo "Error: working tree is dirty; commit or stash first"; exit 1; \ - fi; \ orig=$$(git rev-parse --abbrev-ref HEAD); \ if [ "$$orig" = "HEAD" ]; then \ echo "Error: detached HEAD; checkout a branch first"; exit 1; \ fi; \ + if [ "$$orig" = "canary" ]; then \ + echo "Error: already on canary; checkout a source branch first"; exit 1; \ + fi; \ + stashed=0; \ + if [ -n "$$(git status --porcelain)" ]; then \ + echo "Working tree is dirty; stashing local changes..."; \ + git stash push -u -m "make canary auto-stash from $$orig"; \ + stashed=1; \ + fi; \ cleanup() { \ cur=$$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true); \ if [ "$$cur" != "$$orig" ]; then \ echo "Restoring branch $$orig..."; \ git checkout -q "$$orig"; \ fi; \ + if [ "$$stashed" = "1" ]; then \ + echo "Restoring stashed local changes..."; \ + git stash pop; \ + fi; \ }; \ trap cleanup EXIT; \ - echo "Merging feat -> canary (started from $$orig)..."; \ + echo "Merging $$orig -> canary..."; \ git checkout canary; \ - git merge --no-edit feat; \ + git merge --no-edit "$$orig"; \ git push -u origin canary; \ - echo "Done: feat merged into canary and pushed." + echo "Done: $$orig merged into canary and pushed."