Skip to content

Commit c83ce2c

Browse files
committed
fix(scripts): recover from stale devframe/ when initializing submodule
If `devframe/` exists with leftover content but no `.git` link (e.g. after `git clean -ffdx` or a previous failed install), `git submodule update --init` aborts because the path is non-empty. Detect that state and clear the directory before initializing — there's no git tracking to preserve.
1 parent e678193 commit c83ce2c

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

scripts/sync.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* (never a branch). Run via `pnpm sync` — also runs in `postinstall` so a
66
* fresh clone initializes the submodule automatically.
77
*/
8-
import { existsSync } from 'node:fs'
9-
import { readFile, writeFile } from 'node:fs/promises'
8+
import { existsSync, readdirSync } from 'node:fs'
9+
import { readFile, rm, writeFile } from 'node:fs/promises'
1010
import process from 'node:process'
1111
import { fileURLToPath } from 'node:url'
1212
import { cac } from 'cac'
@@ -63,8 +63,17 @@ async function tryGit(args: string[], opts: { cwd?: string } = {}): Promise<stri
6363
}
6464

6565
async function ensureSubmoduleInit(): Promise<void> {
66-
if (existsSync(resolve(ROOT, SUBMODULE, '.git')))
66+
const submodulePath = resolve(ROOT, SUBMODULE)
67+
if (existsSync(resolve(submodulePath, '.git')))
6768
return
69+
// A non-empty directory without `.git` is leftover from a previous clone
70+
// whose git metadata was wiped (e.g. by `git clean -ffdx`). Submodule init
71+
// refuses to overwrite it, so clear it first — there's no git tracking,
72+
// hence nothing to lose beyond regeneratable build artifacts.
73+
if (existsSync(submodulePath) && readdirSync(submodulePath).length > 0) {
74+
console.log(`[sync] Clearing stale ${SUBMODULE}/ (missing .git link)…`)
75+
await rm(submodulePath, { recursive: true, force: true })
76+
}
6877
console.log(`[sync] Initializing ${SUBMODULE} submodule…`)
6978
await git(['submodule', 'update', '--init', SUBMODULE])
7079
}

0 commit comments

Comments
 (0)