resulgit 1.0.10 → 1.0.12
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 +44 -4
package/package.json
CHANGED
package/resulgit.js
CHANGED
|
@@ -1379,11 +1379,16 @@ async function cmdPush(opts) {
|
|
|
1379
1379
|
const line = firstDiffLine(l || '', r || '')
|
|
1380
1380
|
conflicts.push({ path: p, line })
|
|
1381
1381
|
} else if (changedLocal && !changedRemote) {
|
|
1382
|
+
// Local changed, use local version
|
|
1382
1383
|
if (l !== null) merged[p] = l
|
|
1383
1384
|
} else if (!changedLocal && changedRemote) {
|
|
1385
|
+
// Remote changed, use remote version
|
|
1384
1386
|
if (r !== null) merged[p] = r
|
|
1385
1387
|
} else {
|
|
1386
|
-
|
|
1388
|
+
// No changes - include the file from whatever source has it
|
|
1389
|
+
if (l !== null) merged[p] = l
|
|
1390
|
+
else if (r !== null) merged[p] = r
|
|
1391
|
+
else if (b !== null) merged[p] = b
|
|
1387
1392
|
}
|
|
1388
1393
|
}
|
|
1389
1394
|
if (conflicts.length > 0) {
|
|
@@ -1399,6 +1404,18 @@ async function cmdPush(opts) {
|
|
|
1399
1404
|
}
|
|
1400
1405
|
return
|
|
1401
1406
|
}
|
|
1407
|
+
|
|
1408
|
+
// Check if there are any files to push
|
|
1409
|
+
if (Object.keys(merged).length === 0) {
|
|
1410
|
+
spinnerFail(spinner, 'Nothing to push')
|
|
1411
|
+
if (opts.json === 'true') {
|
|
1412
|
+
print({ error: 'No files to push' }, true)
|
|
1413
|
+
} else {
|
|
1414
|
+
process.stdout.write('No files to push. Add some files first.\n')
|
|
1415
|
+
}
|
|
1416
|
+
return
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1402
1419
|
// Execute pre-push hook
|
|
1403
1420
|
spinnerUpdate(spinner, 'Running pre-push hook...')
|
|
1404
1421
|
try {
|
|
@@ -1413,7 +1430,7 @@ async function cmdPush(opts) {
|
|
|
1413
1430
|
}
|
|
1414
1431
|
|
|
1415
1432
|
const body = { message: localMeta.pendingCommit?.message || (opts.message || 'Push'), files: merged, branchName: remoteMeta.branch }
|
|
1416
|
-
spinnerUpdate(spinner, `Pushing to '${remoteMeta.branch}'...`)
|
|
1433
|
+
spinnerUpdate(spinner, `Pushing ${Object.keys(merged).length} file(s) to '${remoteMeta.branch}'...`)
|
|
1417
1434
|
const url = new URL(`/api/repositories/${remoteMeta.repoId}/commits`, server).toString()
|
|
1418
1435
|
const data = await request('POST', url, body, token)
|
|
1419
1436
|
localMeta.baseCommitId = data.id || remote.commitId || ''
|
|
@@ -2403,9 +2420,32 @@ async function cmdInit(opts) {
|
|
|
2403
2420
|
`\ttoken = ${opts.token || token || ''}`
|
|
2404
2421
|
].join('\n')
|
|
2405
2422
|
await fs.promises.writeFile(path.join(gitDir, 'config'), gitConfig, 'utf8')
|
|
2406
|
-
|
|
2423
|
+
|
|
2424
|
+
let remoteCommitId = ''
|
|
2425
|
+
let baseFiles = {}
|
|
2426
|
+
|
|
2427
|
+
// If remote was created, fetch the initial snapshot to sync baseFiles
|
|
2428
|
+
if (remoteCreated && repoId && server) {
|
|
2429
|
+
try {
|
|
2430
|
+
spinnerUpdate(spinner, 'Syncing with remote...')
|
|
2431
|
+
const snapshot = await fetchRemoteSnapshot(server, repoId, branch, token)
|
|
2432
|
+
remoteCommitId = snapshot.commitId || ''
|
|
2433
|
+
baseFiles = snapshot.files || {}
|
|
2434
|
+
|
|
2435
|
+
// Write the remote files to the local directory (like a clone)
|
|
2436
|
+
for (const [filePath, content] of Object.entries(baseFiles)) {
|
|
2437
|
+
const fullPath = path.join(targetDir, filePath)
|
|
2438
|
+
await fs.promises.mkdir(path.dirname(fullPath), { recursive: true })
|
|
2439
|
+
await fs.promises.writeFile(fullPath, String(content), 'utf8')
|
|
2440
|
+
}
|
|
2441
|
+
} catch (err) {
|
|
2442
|
+
// Ignore sync errors - the repo might be truly empty
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
const remoteMeta = { repoId: repoId, branch, commitId: remoteCommitId, server: opts.server || server || '', token: opts.token || token || '' }
|
|
2407
2447
|
await fs.promises.writeFile(path.join(metaDir, 'remote.json'), JSON.stringify(remoteMeta, null, 2))
|
|
2408
|
-
const localMeta = { baseCommitId:
|
|
2448
|
+
const localMeta = { baseCommitId: remoteCommitId, baseFiles: baseFiles, pendingCommit: null }
|
|
2409
2449
|
await fs.promises.writeFile(path.join(metaDir, 'local.json'), JSON.stringify(localMeta, null, 2))
|
|
2410
2450
|
|
|
2411
2451
|
if (remoteCreated) {
|