resulgit 1.0.9 → 1.0.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/resulgit.js +26 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resulgit",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "A powerful CLI tool for version control system operations - clone, commit, push, pull, merge, branch management, and more",
5
5
  "main": "resulgit.js",
6
6
  "bin": {
package/resulgit.js CHANGED
@@ -2354,7 +2354,7 @@ async function cmdInit(opts) {
2354
2354
  name: repo,
2355
2355
  description: opts.description || '',
2356
2356
  visibility: opts.visibility || 'private',
2357
- initializeWithReadme: false
2357
+ initializeWithReadme: true
2358
2358
  }, token)
2359
2359
  // Use the ID returned by the server (could be numeric or string)
2360
2360
  repoId = String(createRes.id || repo)
@@ -2403,9 +2403,32 @@ async function cmdInit(opts) {
2403
2403
  `\ttoken = ${opts.token || token || ''}`
2404
2404
  ].join('\n')
2405
2405
  await fs.promises.writeFile(path.join(gitDir, 'config'), gitConfig, 'utf8')
2406
- const remoteMeta = { repoId: repoId, branch, commitId: '', server: opts.server || server || '', token: opts.token || token || '' }
2406
+
2407
+ let remoteCommitId = ''
2408
+ let baseFiles = {}
2409
+
2410
+ // If remote was created, fetch the initial snapshot to sync baseFiles
2411
+ if (remoteCreated && repoId && server) {
2412
+ try {
2413
+ spinnerUpdate(spinner, 'Syncing with remote...')
2414
+ const snapshot = await fetchRemoteSnapshot(server, repoId, branch, token)
2415
+ remoteCommitId = snapshot.commitId || ''
2416
+ baseFiles = snapshot.files || {}
2417
+
2418
+ // Write the remote files to the local directory (like a clone)
2419
+ for (const [filePath, content] of Object.entries(baseFiles)) {
2420
+ const fullPath = path.join(targetDir, filePath)
2421
+ await fs.promises.mkdir(path.dirname(fullPath), { recursive: true })
2422
+ await fs.promises.writeFile(fullPath, String(content), 'utf8')
2423
+ }
2424
+ } catch (err) {
2425
+ // Ignore sync errors - the repo might be truly empty
2426
+ }
2427
+ }
2428
+
2429
+ const remoteMeta = { repoId: repoId, branch, commitId: remoteCommitId, server: opts.server || server || '', token: opts.token || token || '' }
2407
2430
  await fs.promises.writeFile(path.join(metaDir, 'remote.json'), JSON.stringify(remoteMeta, null, 2))
2408
- const localMeta = { baseCommitId: '', baseFiles: {}, pendingCommit: null }
2431
+ const localMeta = { baseCommitId: remoteCommitId, baseFiles: baseFiles, pendingCommit: null }
2409
2432
  await fs.promises.writeFile(path.join(metaDir, 'local.json'), JSON.stringify(localMeta, null, 2))
2410
2433
 
2411
2434
  if (remoteCreated) {