mirror of
https://github.com/peakoss/anti-slop
synced 2026-11-28 13:37:41 +08:00
feat(script): add branch and ahead prerequisite checks
This commit is contained in:
1 file changed
+14
-1
+14
-1
@@ -11,10 +11,23 @@ check_prerequisites() {
|
||||
command -v git > /dev/null 2>&1 || die "git is not installed. Install it from https://git-scm.com"
|
||||
git rev-parse --is-inside-work-tree > /dev/null 2>&1 || die "Not a git repository"
|
||||
|
||||
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||
local current_branch
|
||||
current_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [ "$current_branch" != "main" ]; then
|
||||
die "Must be on ${BOLD}main${OFF}${RED} branch (current: ${BOLD}$current_branch${OFF}${RED})${OFF}"
|
||||
fi
|
||||
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
die "Working tree is not clean. Commit or stash your changes first."
|
||||
fi
|
||||
|
||||
git fetch origin --quiet 2>/dev/null || die "Could not fetch from remote"
|
||||
local ahead
|
||||
ahead=$(git rev-list --count origin/main..HEAD 2>/dev/null || echo "0")
|
||||
if [ "$ahead" -gt 0 ]; then
|
||||
die "Local branch is $ahead commit(s) ahead of origin/main. Push your changes first."
|
||||
fi
|
||||
|
||||
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||
PACKAGE_JSON="$REPO_ROOT/package.json"
|
||||
[ -f "$PACKAGE_JSON" ] || die "package.json not found"
|
||||
|
||||
Reference in new issue
Block a user