botrun-mcli 0.2.1 → 0.2.2
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/src/commands/memory/sync.mjs +34 -9
package/package.json
CHANGED
|
@@ -6,23 +6,48 @@ export async function syncMemory(options = {}) {
|
|
|
6
6
|
const config = await loadConfig(options.configPath);
|
|
7
7
|
const dataDir = options.dataDir || join(getBasePath(), 'data');
|
|
8
8
|
|
|
9
|
-
const result = { synced: [], skipped: [] };
|
|
9
|
+
const result = { synced: [], pulled: [], skipped: [] };
|
|
10
10
|
|
|
11
11
|
for (const [name, scope] of Object.entries(config.scopes)) {
|
|
12
12
|
const cloneDir = join(dataDir, name);
|
|
13
|
+
let didPull = false;
|
|
14
|
+
let didPush = false;
|
|
13
15
|
|
|
16
|
+
// 1. Always pull remote changes first
|
|
17
|
+
try {
|
|
18
|
+
const before = await gitExec(['-C', cloneDir, 'rev-parse', 'HEAD']);
|
|
19
|
+
await gitExec(['-C', cloneDir, 'pull', '--rebase']);
|
|
20
|
+
const after = await gitExec(['-C', cloneDir, 'rev-parse', 'HEAD']);
|
|
21
|
+
if (before !== after) didPull = true;
|
|
22
|
+
} catch {
|
|
23
|
+
// pull may fail if no upstream set; try setting it
|
|
24
|
+
try {
|
|
25
|
+
const branch = await gitExec(['-C', cloneDir, 'rev-parse', '--abbrev-ref', 'HEAD']);
|
|
26
|
+
await gitExec(['-C', cloneDir, 'branch', '--set-upstream-to', `origin/${branch}`, branch]);
|
|
27
|
+
const before = await gitExec(['-C', cloneDir, 'rev-parse', 'HEAD']);
|
|
28
|
+
await gitExec(['-C', cloneDir, 'pull', '--rebase']);
|
|
29
|
+
const after = await gitExec(['-C', cloneDir, 'rev-parse', 'HEAD']);
|
|
30
|
+
if (before !== after) didPull = true;
|
|
31
|
+
} catch {
|
|
32
|
+
// still failed, continue
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 2. Check for local uncommitted changes and push
|
|
14
37
|
const status = await gitExec(['-C', cloneDir, 'status', '--porcelain']);
|
|
38
|
+
if (status) {
|
|
39
|
+
await gitExec(['-C', cloneDir, 'add', '-A']);
|
|
40
|
+
await gitExec(['-C', cloneDir, 'commit', '-m', `bm: update ${name} memories`]);
|
|
41
|
+
await gitExec(['-C', cloneDir, 'push']);
|
|
42
|
+
didPush = true;
|
|
43
|
+
}
|
|
15
44
|
|
|
16
|
-
if (
|
|
45
|
+
if (didPull || didPush) {
|
|
46
|
+
result.synced.push(name);
|
|
47
|
+
if (didPull) result.pulled.push(name);
|
|
48
|
+
} else {
|
|
17
49
|
result.skipped.push(name);
|
|
18
|
-
continue;
|
|
19
50
|
}
|
|
20
|
-
|
|
21
|
-
await gitExec(['-C', cloneDir, 'add', '-A']);
|
|
22
|
-
await gitExec(['-C', cloneDir, 'commit', '-m', `bm: update ${name} memories`]);
|
|
23
|
-
await gitExec(['-C', cloneDir, 'pull', '--rebase']);
|
|
24
|
-
await gitExec(['-C', cloneDir, 'push']);
|
|
25
|
-
result.synced.push(name);
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
return result;
|