Repository navigation
Expand file tree
/
Copy pathgit.sh
More file actions
executable file
·94 lines (79 loc) · 3.95 KB
/
Copy pathgit.sh
File metadata and controls
executable file
·94 lines (79 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# Stage, commit (timestamped), pull --rebase, push — with safety guards.
#
# Guards added after the 2026-10-03 incident (conflicted rebase left the repo
# in detached HEAD with conflict markers committed into project JSON files):
# - refuse to run during an in-progress rebase/merge/cherry-pick
# - refuse to run on detached HEAD
# - refuse to commit staged conflict markers or invalid JSON
# - never proceed to push if pull --rebase fails
set -e
# Always operate on this project, regardless of the caller's directory.
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
fail() { echo "❌ $*" >&2; exit 1; }
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) || fail "Not a git repository."
# --- Guard 1: never start from a half-finished rebase/merge/cherry-pick ---
if [ -d "$GIT_DIR/rebase-merge" ] || [ -d "$GIT_DIR/rebase-apply" ]; then
fail "Rebase in progress. Finish it first: git status → fix files → git add <files> → git rebase --continue (or git rebase --abort). Then re-run this script."
fi
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
fail "Merge in progress. Finish it first: git status → fix files → git add <files> → git commit (or git merge --abort). Then re-run this script."
fi
if [ -f "$GIT_DIR/CHERRY_PICK_HEAD" ]; then
fail "Cherry-pick in progress. Finish it first (git cherry-pick --continue/--abort). Then re-run this script."
fi
# --- Guard 2: never commit/push from detached HEAD ---
BRANCH=$(git symbolic-ref -q --short HEAD) || fail "Detached HEAD. Check out your branch first (e.g. git checkout main), then re-run this script."
echo "⏳ Staging changes..."
# Stage all changes (including new files) so helper scripts and other
# untracked files are committed alongside data updates.
git add -A
# Check if anything was actually staged
if git diff --cached --quiet; then
echo "✅ No changes detected. Working tree is clean."
exit 0
fi
# --- Guard 3: never commit conflict markers (git diff --check flags them) ---
if ! git diff --cached --check; then
fail "Staged changes contain conflict markers or whitespace errors. Unstage, resolve the conflicts, then re-run this script."
fi
# --- Guard 4: never commit invalid JSON (e.g. a badly resolved project JSON files) ---
if command -v python3 >/dev/null 2>&1; then
invalid=0
while IFS= read -r -d '' f; do
if ! git show ":$f" 2>/dev/null | python3 -m json.tool >/dev/null 2>&1; then
echo "❌ Invalid JSON in staged file: $f" >&2
invalid=1
fi
done < <(git diff --cached --name-only -z --diff-filter=ACM -- '*.json')
if [ "$invalid" -ne 0 ]; then
fail "Aborting: fix the JSON files above, stage them, then re-run this script."
fi
else
echo "⚠️ python3 not found, skipping JSON validation." >&2
fi
# Generate human-readable timestamp
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
echo "📝 Committing changes with timestamp..."
git commit -m "reactos update - $TIMESTAMP"
echo "🔄 Pulling latest remote changes..."
if ! git pull --rebase origin main; then
echo "❌ git pull --rebase failed — most likely a merge conflict." >&2
echo " The rebase is paused; your commit is safe. To recover:" >&2
echo " 1. git status # see conflicted files" >&2
echo " 2. fix the files (no '<<<<<<<' markers left, JSON must parse)" >&2
echo " 3. git add <fixed files>" >&2
echo " 4. git rebase --continue (or git rebase --abort to give up)" >&2
echo " 5. re-run this script to push" >&2
exit 1
fi
# --- Guard 5: pull --rebase must have left us on a branch, not detached ---
git symbolic-ref -q HEAD >/dev/null || fail "Detached HEAD after rebase. Run git status / git rebase --continue first."
echo "🚀 Pushing changes to remote..."
if ! git push; then
echo "❌ git push failed." >&2
echo " If it says 'not currently on a branch', a rebase/merge is still" >&2
echo " in progress — run git status and finish it first." >&2
exit 1
fi
echo "🎉 Successfully synced!"