| @@ -1,6 +1,6 @@ |
| 1 | 1 | import { spinner, log } from "@clack/prompts"; |
| 2 | 2 | import { execSync } from "node:child_process"; |
| 3 | | import { writeFileSync, existsSync } from "node:fs"; |
| 3 | import { writeFileSync, existsSync, mkdirSync } from "node:fs"; |
| 4 | 4 | import { join, resolve } from "node:path"; |
| 5 | 5 | import { hubRequest } from "../api.js"; |
| 6 | 6 | import { getHub } from "../config.js"; |
| @@ -52,20 +52,25 @@ |
| 52 | 52 | const dest = args.find((a, i) => i > args.indexOf(slug) && !a.startsWith("--")) ?? repoName; |
| 53 | 53 | const destPath = resolve(dest); |
| 54 | 54 | |
| 55 | | // Run sl clone |
| 56 | | log.step(`Cloning into ${dest}`); |
| 55 | // Use sl init + pull (not sl clone, which uses getbundle protocol that doesn't work with Mononoke) |
| 56 | const hub = await getHub(); |
| 57 | |
| 58 | const s2 = spinner(); |
| 59 | s2.start(`Cloning into ${dest}`); |
| 60 | mkdirSync(destPath, { recursive: true }); |
| 61 | execSync(`sl init --config init.prefer-git=false --config format.use-remotefilelog=true "${destPath}"`, { stdio: "pipe" }); |
| 62 | |
| 63 | // Write config with remote and auth settings before pulling |
| 64 | writeFileSync(join(destPath, ".sl", "config"), buildSlConfig({ name: repoName, owner_name: owner, default_branch: repo.default_branch }, hub)); |
| 65 | |
| 66 | // Pull and checkout |
| 57 | 67 | try { |
| 58 | | execSync(`sl clone slapi:${repoName} ${dest}`, { stdio: "inherit" }); |
| 68 | execSync(`sl pull`, { cwd: destPath, stdio: "pipe" }); |
| 69 | execSync(`sl goto ${repo.default_branch}`, { cwd: destPath, stdio: "pipe" }); |
| 70 | s2.stop(`Cloned ${owner}/${repoName}`); |
| 59 | 71 | } catch { |
| 60 | | // sl clone of empty repos exits non-zero — check if .sl was created |
| 61 | | if (!existsSync(join(destPath, ".sl"))) { |
| 62 | | // Clone truly failed |
| 63 | | process.exit(1); |
| 64 | | } |
| 72 | s2.stop(`Cloned ${owner}/${repoName} (empty repository)`); |
| 65 | 73 | } |
| 66 | 74 | |
| 67 | | // Write proper .sl/config |
| 68 | | const hub = await getHub(); |
| 69 | | writeFileSync(join(destPath, ".sl", "config"), buildSlConfig({ name: repoName, owner_name: owner, default_branch: repo.default_branch }, hub)); |
| 70 | 75 | log.success(`Cloned ${owner}/${repoName} into ${dest}`); |
| 71 | 76 | } |
| 72 | 77 | |