jettypod 4.2.5 → 4.2.7
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/lib/database.js +24 -5
- package/lib/worktree-manager.js +19 -1
- package/package.json +1 -1
package/lib/database.js
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
const sqlite3 = require('sqlite3').verbose();
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const { getGitRoot } = require('./git-root');
|
|
4
5
|
|
|
5
6
|
// Singleton database connection
|
|
6
7
|
let db = null;
|
|
7
8
|
let cachedJettypodDir = null;
|
|
8
9
|
let cachedDbPath = null;
|
|
10
|
+
let cachedGitRoot = null;
|
|
9
11
|
let isClosing = false;
|
|
10
12
|
let migrationPromise = null;
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Get the root directory for jettypod operations
|
|
16
|
+
* Always returns the main repo, even when called from a worktree
|
|
17
|
+
*/
|
|
18
|
+
function getRepoRoot() {
|
|
19
|
+
if (!cachedGitRoot) {
|
|
20
|
+
try {
|
|
21
|
+
cachedGitRoot = getGitRoot();
|
|
22
|
+
} catch (err) {
|
|
23
|
+
// Fall back to cwd if not in a git repo (e.g., during init)
|
|
24
|
+
cachedGitRoot = process.cwd();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return cachedGitRoot;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Dynamic getters for paths (always use main repo, not worktree)
|
|
13
31
|
function getJettypodDir() {
|
|
14
|
-
const
|
|
15
|
-
if (!cachedJettypodDir ||
|
|
16
|
-
cachedJettypodDir = path.join(
|
|
32
|
+
const root = getRepoRoot();
|
|
33
|
+
if (!cachedJettypodDir || cachedJettypodDir !== path.join(root, '.jettypod')) {
|
|
34
|
+
cachedJettypodDir = path.join(root, '.jettypod');
|
|
17
35
|
// Use separate database for tests
|
|
18
36
|
const dbFileName = process.env.NODE_ENV === 'test' ? 'test-work.db' : 'work.db';
|
|
19
37
|
cachedDbPath = path.join(cachedJettypodDir, dbFileName);
|
|
@@ -59,7 +77,7 @@ function ensureJettyPodDir() {
|
|
|
59
77
|
function getDb() {
|
|
60
78
|
// Check if directory changed - if so, reset connection
|
|
61
79
|
const dbFileName = process.env.NODE_ENV === 'test' ? 'test-work.db' : 'work.db';
|
|
62
|
-
const currentPath = path.join(
|
|
80
|
+
const currentPath = path.join(getRepoRoot(), '.jettypod', dbFileName);
|
|
63
81
|
if (db && cachedDbPath && cachedDbPath !== currentPath) {
|
|
64
82
|
// Directory changed - abandon old connection without closing
|
|
65
83
|
// Attempting to close with active prepared statements causes FATAL errors
|
|
@@ -252,6 +270,7 @@ function resetDb() {
|
|
|
252
270
|
db = null;
|
|
253
271
|
cachedJettypodDir = null;
|
|
254
272
|
cachedDbPath = null;
|
|
273
|
+
cachedGitRoot = null;
|
|
255
274
|
isClosing = false;
|
|
256
275
|
migrationPromise = null;
|
|
257
276
|
}
|
package/lib/worktree-manager.js
CHANGED
|
@@ -177,7 +177,25 @@ async function createWorktree(workItem, options = {}) {
|
|
|
177
177
|
throw new Error(`Failed to create .jettypod symlink: ${symlinkErr.message}`);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
// Step 5:
|
|
180
|
+
// Step 5: Symlink .env files from main repo
|
|
181
|
+
// Environment files are typically gitignored, so worktrees don't get them
|
|
182
|
+
try {
|
|
183
|
+
const envFiles = fs.readdirSync(gitRoot).filter(f => f.startsWith('.env'));
|
|
184
|
+
for (const envFile of envFiles) {
|
|
185
|
+
const envSource = path.join(gitRoot, envFile);
|
|
186
|
+
const envTarget = path.join(worktreePath, envFile);
|
|
187
|
+
|
|
188
|
+
// Only symlink if source is a file and target doesn't exist
|
|
189
|
+
if (fs.statSync(envSource).isFile() && !fs.existsSync(envTarget)) {
|
|
190
|
+
fs.symlinkSync(envSource, envTarget);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} catch (envErr) {
|
|
194
|
+
// Non-fatal - log warning but continue
|
|
195
|
+
console.warn(`Warning: Could not symlink .env files: ${envErr.message}`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Step 6: Return the created worktree record
|
|
181
199
|
const worktree = await new Promise((resolve, reject) => {
|
|
182
200
|
db.get('SELECT * FROM worktrees WHERE id = ?', [worktreeId], (err, row) => {
|
|
183
201
|
if (err) reject(err);
|