sandboxbox 3.0.11 → 3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/sandbox.js +60 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sandboxbox",
3
- "version": "3.0.11",
3
+ "version": "3.0.12",
4
4
  "description": "Lightweight process containment sandbox for CLI tools - Playwright, Claude Code, and more. Pure Node.js, no dependencies.",
5
5
  "type": "module",
6
6
  "main": "cli.js",
package/utils/sandbox.js CHANGED
@@ -7,31 +7,60 @@ export function createSandbox(projectDir) {
7
7
  const sandboxDir = mkdtempSync(join(tmpdir(), 'sandboxbox-'));
8
8
  const workspaceDir = join(sandboxDir, 'workspace');
9
9
 
10
- // Batch git operations for better performance
11
- const gitCommands = [
12
- `git config --global --add safe.directory "${projectDir}"`,
13
- `git config --global --add safe.directory "${projectDir}/.git"`,
14
- // Use shallow clone for faster checkout (depth 1 = current commit only)
15
- `git clone --depth 1 --no-tags "${projectDir}" "${workspaceDir}"`
16
- ];
17
-
18
- // Configure host repo to accept pushes (run in project directory)
10
+ // Ensure host directory is a git repository
11
+ if (!existsSync(join(projectDir, '.git'))) {
12
+ // Initialize git repository in host directory if it doesn't exist
13
+ execSync(`git init "${projectDir}"`, {
14
+ stdio: 'pipe',
15
+ shell: true,
16
+ windowsHide: true
17
+ });
18
+ }
19
+
20
+ // Configure global git safe directories
21
+ execSync(`git config --global --add safe.directory "${projectDir}"`, {
22
+ stdio: 'pipe',
23
+ shell: true,
24
+ windowsHide: true
25
+ });
26
+ execSync(`git config --global --add safe.directory "${projectDir}/.git"`, {
27
+ stdio: 'pipe',
28
+ shell: true,
29
+ windowsHide: true
30
+ });
31
+
32
+ // Configure host repository to accept pushes to current branch
19
33
  execSync(`cd "${projectDir}" && git config receive.denyCurrentBranch updateInstead`, {
20
34
  stdio: 'pipe',
21
35
  shell: true,
22
36
  windowsHide: true
23
37
  });
24
38
 
25
- // Execute git commands in parallel where possible
26
- gitCommands.forEach(cmd => {
27
- execSync(cmd, {
39
+ // Copy/clone the project to workspace
40
+ if (existsSync(join(projectDir, '.git'))) {
41
+ // If it's a git repo, do a shallow clone
42
+ execSync(`git clone --depth 1 --no-tags "${projectDir}" "${workspaceDir}"`, {
28
43
  stdio: 'pipe',
29
44
  shell: true,
30
45
  windowsHide: true
31
46
  });
32
- });
47
+ } else {
48
+ // If not a git repo, just copy the files
49
+ mkdirSync(workspaceDir, { recursive: true });
50
+ execSync(`cp -r "${projectDir}"/* "${workspaceDir}/"`, {
51
+ stdio: 'pipe',
52
+ shell: true,
53
+ windowsHide: true
54
+ });
55
+ // Initialize git in workspace
56
+ execSync(`git init "${workspaceDir}"`, {
57
+ stdio: 'pipe',
58
+ shell: true,
59
+ windowsHide: true
60
+ });
61
+ }
33
62
 
34
- // Set up host repo as origin in sandbox (only if not already exists)
63
+ // Set up host repo as origin in sandbox (pointing to host directory)
35
64
  try {
36
65
  execSync(`git remote add origin "${projectDir}"`, {
37
66
  cwd: workspaceDir,
@@ -47,6 +76,23 @@ export function createSandbox(projectDir) {
47
76
  });
48
77
  }
49
78
 
79
+ // Set up upstream tracking for current branch
80
+ try {
81
+ const currentBranch = execSync(`git branch --show-current`, {
82
+ cwd: workspaceDir,
83
+ encoding: 'utf8',
84
+ stdio: 'pipe'
85
+ }).trim();
86
+
87
+ execSync(`git branch --set-upstream-to=origin/${currentBranch} ${currentBranch}`, {
88
+ cwd: workspaceDir,
89
+ stdio: 'pipe',
90
+ shell: true
91
+ });
92
+ } catch (e) {
93
+ // Upstream may not exist yet, ignore error
94
+ }
95
+
50
96
  // Batch fetch git identity settings for efficiency
51
97
  const gitSettings = execSync(`git config --global --get user.name && git config --global --get user.email && git config --global --get color.ui`, {
52
98
  stdio: 'pipe',