Repository: jetpack-io/devbox
Pull request #1920 (2024-03-22 20:53:23)

Support Project Directory having spaces
## Summary
In aid of #1914

Added some basic support for spaces. I think this requires more extensive testing around:
1. plugins
2. flake packages

I should try to have the examples tests run in cicd with a space in their path.


## How was it tested?

```
mkdir -p `/Users/<omitted>/code/jetpack/devbox-projects/path with space`
devbox init
devbox shell
devbox add hello
devbox add cowsay
```

could run:
```
cowsay hello
```

set `export FISH=$(which fish)` and repeat the above steps




savil: * **#1920** <a href="https://app.graphite.dev/github/pr/jetpack-io/devbox/1920?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈
* `main`

This stack of pull requests is managed by Graphite. <a href="https://stacking.dev/?utm_source=stack-comment">Learn more about stacking.</a>
<h2></h2>

 Join @savil and the rest of your teammates on <a href="https://graphite.dev?utm-source=stack-comment"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="11px" height="11px"/> <b>Graphite</b></a>
  <!-- Current dependencies on/for this PR: -->

Patch:
diff --git a/internal/devbox/shellrc.tmpl b/internal/devbox/shellrc.tmpl
index 6f0e5f52..44b4780d 100644
--- a/internal/devbox/shellrc.tmpl
+++ b/internal/devbox/shellrc.tmpl
@@ -56,7 +56,7 @@ working_dir="$(pwd)"
 cd "{{ .ProjectDir }}" || exit
 
 # Source the hooks file, which contains the project's init hooks and plugin hooks.
-. {{ .HooksFilePath }}
+. "{{ .HooksFilePath }}"
 
 cd "$working_dir" || exit
 
diff --git a/internal/devbox/shellrc_fish.tmpl b/internal/devbox/shellrc_fish.tmpl
index a50b3fb2..26ecfb7e 100644
--- a/internal/devbox/shellrc_fish.tmpl
+++ b/internal/devbox/shellrc_fish.tmpl
@@ -59,7 +59,7 @@ set workingDir (pwd)
 cd "{{ .ProjectDir }}" || exit
 
 # Source the hooks file, which contains the project's init hooks and plugin hooks.
-source {{ .HooksFilePath }}
+source "{{ .HooksFilePath }}"
 
 cd "$workingDir" || exit
 
diff --git a/internal/nix/nix.go b/internal/nix/nix.go
index 0f858d17..47075019 100644
--- a/internal/nix/nix.go
+++ b/internal/nix/nix.go
@@ -19,6 +19,7 @@
 	"go.jetpack.io/devbox/internal/boxcli/featureflag"
 	"go.jetpack.io/devbox/internal/boxcli/usererr"
 	"go.jetpack.io/devbox/internal/redact"
+	"go.jetpack.io/devbox/nix/flake"
 
 	"go.jetpack.io/devbox/internal/debug"
 )
@@ -69,15 +70,19 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn
 		return nil, errors.WithStack(err)
 	}
 
+	flakeRef, err := flake.ParseRef("path:" + flakeDirResolved)
+	if err != nil {
+		return nil, err
+	}
+
 	if len(data) == 0 {
 		cmd := exec.CommandContext(
 			ctx,
-			"nix", "print-dev-env",
-			"path:"+flakeDirResolved,
+			"nix", "print-dev-env", flakeRef.String(),
 		)
 		cmd.Args = append(cmd.Args, ExperimentalFlags()...)
 		cmd.Args = append(cmd.Args, "--json")
-		debug.Log("Running print-dev-env cmd: %s\n", cmd)
+		debug.Log("Running print-dev-env cmd: %s\n\n\n", cmd)
 		data, err = cmd.Output()
 		if insecure, insecureErr := IsExitErrorInsecurePackage(err, "" /*pkgName*/, "" /*installable*/); insecure {
 			return nil, insecureErr
diff --git a/internal/shellgen/tmpl/init-hook-wrapper.tmpl b/internal/shellgen/tmpl/init-hook-wrapper.tmpl
index abe3d4ce..3da5fddd 100644
--- a/internal/shellgen/tmpl/init-hook-wrapper.tmpl
+++ b/internal/shellgen/tmpl/init-hook-wrapper.tmpl
@@ -5,5 +5,5 @@ Code here should be fish and POSIX compatible. That's why we use export to
 remove the value
 */ -}}
 export {{ .InitHookHash }}=true
-. {{ .RawHooksFile }}
+. "{{ .RawHooksFile }}"
 export {{ .InitHookHash }}=""
diff --git a/internal/shellgen/tmpl/script-wrapper.tmpl b/internal/shellgen/tmpl/script-wrapper.tmpl
index f6b04721..d048c083 100644
--- a/internal/shellgen/tmpl/script-wrapper.tmpl
+++ b/internal/shellgen/tmpl/script-wrapper.tmpl
@@ -9,7 +9,7 @@
 
 if [ -z "${{ .InitHookHash }}" ]; then
     {{/* init hooks will export InitHookHash ensuring no recursive sourcing*/ -}}
-    . {{ .InitHookPath }}
+    . "{{ .InitHookPath }}"
 fi
 
 {{ .Body }}


Test patch:
diff --git a/internal/devbox/testdata/shellrc/basic/shellrc.golden b/internal/devbox/testdata/shellrc/basic/shellrc.golden
index 9e110a4a..19e5813c 100644
--- a/internal/devbox/testdata/shellrc/basic/shellrc.golden
+++ b/internal/devbox/testdata/shellrc/basic/shellrc.golden
@@ -21,7 +21,7 @@ working_dir="$(pwd)"
 cd "/path/to/projectDir" || exit
 
 # Source the hooks file, which contains the project's init hooks and plugin hooks.
-. /path/to/projectDir/.devbox/gen/scripts/.hooks.sh
+. "/path/to/projectDir/.devbox/gen/scripts/.hooks.sh"
 
 cd "$working_dir" || exit
 
diff --git a/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden b/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden
index e7ac3d7b..f21ece85 100644
--- a/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden
+++ b/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden
@@ -15,7 +15,7 @@ working_dir="$(pwd)"
 cd "/path/to/projectDir" || exit
 
 # Source the hooks file, which contains the project's init hooks and plugin hooks.
-. /path/to/projectDir/.devbox/gen/scripts/.hooks.sh
+. "/path/to/projectDir/.devbox/gen/scripts/.hooks.sh"
 
 cd "$working_dir" || exit