resulgit 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/resulgit.js +40 -11
package/package.json
CHANGED
package/resulgit.js
CHANGED
|
@@ -991,6 +991,14 @@ async function fetchRemoteSnapshot(server, repo, branch, token) {
|
|
|
991
991
|
if (branch) url.searchParams.set('branch', branch)
|
|
992
992
|
const res = await fetch(url.toString(), { headers })
|
|
993
993
|
if (!res.ok) {
|
|
994
|
+
// For new/empty repos, return empty snapshot instead of throwing
|
|
995
|
+
if (res.status === 404 || res.status === 500) {
|
|
996
|
+
// Check if this is a "new repo" scenario
|
|
997
|
+
const text = await res.text()
|
|
998
|
+
if (text.includes('not found') || text.includes('empty') || text.includes('no commits') || res.status === 500) {
|
|
999
|
+
return { files: {}, commitId: '' }
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
994
1002
|
const text = await res.text()
|
|
995
1003
|
throw new Error(text || 'snapshot failed')
|
|
996
1004
|
}
|
|
@@ -2332,8 +2340,13 @@ async function cmdInit(opts) {
|
|
|
2332
2340
|
const spinner = createSpinner(`Initializing repository${repo ? ` '${repo}'` : ''}...`, opts.json)
|
|
2333
2341
|
|
|
2334
2342
|
let repoId = repo
|
|
2335
|
-
|
|
2336
|
-
|
|
2343
|
+
let remoteCreated = false
|
|
2344
|
+
|
|
2345
|
+
// If a repo name is provided and we have server, try to create remote repo
|
|
2346
|
+
if (repo && server) {
|
|
2347
|
+
if (!token) {
|
|
2348
|
+
spinnerUpdate(spinner, 'No auth token set. Run "resulgit auth login" first for remote repo creation.')
|
|
2349
|
+
}
|
|
2337
2350
|
try {
|
|
2338
2351
|
spinnerUpdate(spinner, 'Creating remote repository...')
|
|
2339
2352
|
const createUrl = new URL('/api/repositories', server).toString()
|
|
@@ -2345,20 +2358,26 @@ async function cmdInit(opts) {
|
|
|
2345
2358
|
}, token)
|
|
2346
2359
|
// Use the ID returned by the server (could be numeric or string)
|
|
2347
2360
|
repoId = String(createRes.id || repo)
|
|
2348
|
-
|
|
2361
|
+
remoteCreated = true
|
|
2362
|
+
spinnerUpdate(spinner, `Remote repository '${repo}' created (ID: ${repoId})`)
|
|
2349
2363
|
} catch (err) {
|
|
2350
|
-
// If repo already exists, try to fetch its ID
|
|
2351
|
-
if (err.message && err.message.includes('409')) {
|
|
2364
|
+
// If repo already exists (409), try to fetch its ID
|
|
2365
|
+
if (err.message && (err.message.includes('409') || err.message.includes('already exists'))) {
|
|
2352
2366
|
spinnerUpdate(spinner, `Remote repository '${repo}' already exists, linking...`)
|
|
2353
2367
|
try {
|
|
2354
2368
|
const listUrl = new URL('/api/repositories', server).toString()
|
|
2355
2369
|
const repos = await request('GET', listUrl, null, token)
|
|
2356
2370
|
const found = (repos || []).find(r => r.name === repo)
|
|
2357
|
-
if (found)
|
|
2371
|
+
if (found) {
|
|
2372
|
+
repoId = String(found.id)
|
|
2373
|
+
remoteCreated = true
|
|
2374
|
+
}
|
|
2358
2375
|
} catch { /* ignore */ }
|
|
2376
|
+
} else if (err.message && err.message.includes('401')) {
|
|
2377
|
+
spinnerUpdate(spinner, 'Authentication required. Run "resulgit auth login" to set up credentials.')
|
|
2359
2378
|
} else {
|
|
2360
2379
|
// Other error - continue with local init only
|
|
2361
|
-
spinnerUpdate(spinner, `Could not create remote repo: ${err.message}
|
|
2380
|
+
spinnerUpdate(spinner, `Could not create remote repo: ${err.message}`)
|
|
2362
2381
|
}
|
|
2363
2382
|
}
|
|
2364
2383
|
}
|
|
@@ -2389,8 +2408,14 @@ async function cmdInit(opts) {
|
|
|
2389
2408
|
const localMeta = { baseCommitId: '', baseFiles: {}, pendingCommit: null }
|
|
2390
2409
|
await fs.promises.writeFile(path.join(metaDir, 'local.json'), JSON.stringify(localMeta, null, 2))
|
|
2391
2410
|
|
|
2392
|
-
|
|
2393
|
-
|
|
2411
|
+
if (remoteCreated) {
|
|
2412
|
+
spinnerSuccess(spinner, `Initialized repository '${repo}' in ${targetDir} (remote linked)`)
|
|
2413
|
+
} else if (repo) {
|
|
2414
|
+
spinnerSuccess(spinner, `Initialized local repository in ${targetDir} (remote not created - check auth)`)
|
|
2415
|
+
} else {
|
|
2416
|
+
spinnerSuccess(spinner, `Initialized repository in ${targetDir}`)
|
|
2417
|
+
}
|
|
2418
|
+
print({ initialized: targetDir, branch, repoId: repoId, remoteCreated }, opts.json === 'true')
|
|
2394
2419
|
}
|
|
2395
2420
|
|
|
2396
2421
|
async function cmdMv(opts) {
|
|
@@ -3229,8 +3254,12 @@ async function main() {
|
|
|
3229
3254
|
return
|
|
3230
3255
|
}
|
|
3231
3256
|
if (cmd[0] === 'init') {
|
|
3232
|
-
|
|
3233
|
-
|
|
3257
|
+
// Allow positional repo name: resulgit init MyRepo
|
|
3258
|
+
if (cmd[1] && !cmd[1].startsWith('-') && !opts.repo) {
|
|
3259
|
+
opts.repo = cmd[1];
|
|
3260
|
+
}
|
|
3261
|
+
await cmdInit(opts);
|
|
3262
|
+
return;
|
|
3234
3263
|
}
|
|
3235
3264
|
if (cmd[0] === 'remote') {
|
|
3236
3265
|
await cmdRemote(cmd[1], opts)
|