Spaces:
Running
Running
Commit ·
84f5427
1
Parent(s): 411b90c
fix: verify staging remote before write/commit on --push (no dangling commit)
Browse files
.claude/skills/sync-nowai-leaderboard/sync.mjs
CHANGED
|
@@ -128,6 +128,18 @@ async function main() {
|
|
| 128 |
|
| 129 |
// 6. Write + commit (apply and push only; never in check mode).
|
| 130 |
if (mode !== 'apply' && mode !== 'push') return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
await mkdir(dirname(dataPath), { recursive: true });
|
| 132 |
await writeFile(dataPath, JSON.stringify(newData, null, 2) + '\n');
|
| 133 |
git(root, ['add', dataPath]);
|
|
@@ -136,15 +148,8 @@ async function main() {
|
|
| 136 |
git(root, ['commit', '-m', msg]);
|
| 137 |
console.log('[sync] committed.');
|
| 138 |
|
| 139 |
-
// 7. Push (staging only) if requested.
|
| 140 |
if (mode === 'push') {
|
| 141 |
-
// Hard guard: refuse to push unless `origin` is the staging Space.
|
| 142 |
-
const originUrl = git(root, ['remote', 'get-url', 'origin']).trim();
|
| 143 |
-
if (!originUrl.includes(STAGING_SLUG)) {
|
| 144 |
-
console.error(`[sync] refusing to push: origin is not the staging remote (${originUrl}).`);
|
| 145 |
-
await notify(`Leaderboard sync: push refused — origin is not staging (${originUrl}). Commit kept locally.`);
|
| 146 |
-
process.exit(4);
|
| 147 |
-
}
|
| 148 |
try {
|
| 149 |
git(root, ['push', 'origin', 'HEAD:main']);
|
| 150 |
console.log('[sync] pushed to origin (staging).');
|
|
|
|
| 128 |
|
| 129 |
// 6. Write + commit (apply and push only; never in check mode).
|
| 130 |
if (mode !== 'apply' && mode !== 'push') return;
|
| 131 |
+
|
| 132 |
+
// For push: verify `origin` is staging BEFORE writing/committing, so a push
|
| 133 |
+
// from a wrong checkout can't leave a dangling local commit to roll back.
|
| 134 |
+
if (mode === 'push') {
|
| 135 |
+
const originUrl = git(root, ['remote', 'get-url', 'origin']).trim();
|
| 136 |
+
if (!originUrl.includes(STAGING_SLUG)) {
|
| 137 |
+
console.error(`[sync] refusing to push: origin is not the staging remote (${originUrl}). Nothing written.`);
|
| 138 |
+
await notify(`Leaderboard sync: push refused — origin is not staging (${originUrl}). Nothing committed.`);
|
| 139 |
+
process.exit(4);
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
await mkdir(dirname(dataPath), { recursive: true });
|
| 144 |
await writeFile(dataPath, JSON.stringify(newData, null, 2) + '\n');
|
| 145 |
git(root, ['add', dataPath]);
|
|
|
|
| 148 |
git(root, ['commit', '-m', msg]);
|
| 149 |
console.log('[sync] committed.');
|
| 150 |
|
| 151 |
+
// 7. Push (staging only) if requested. Origin already verified as staging above.
|
| 152 |
if (mode === 'push') {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
try {
|
| 154 |
git(root, ['push', 'origin', 'HEAD:main']);
|
| 155 |
console.log('[sync] pushed to origin (staging).');
|