Skip to content

Commit f050ab8

Browse files
authored
[state] Ignore shell mismatch for run (#1774)
## Summary This is a bit hacky, but was smallest, safest I could come up with. This fixes the following case: * User uses fish as shell * User adds `devbox run` in their init hook * User gets warning that environment is stale. This happens because shell doesn't match, but we don't really care that shell doesn't match for `run`. We only care for `shell` because we use different shellrc for fish vs POSIX. ## How was it tested? Added `devbox run echo foo` to init hook. Then ran ``` SHELL=fish devbox run echo bar ```
1 parent 799368c commit f050ab8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

internal/devbox/devbox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
233233
return err
234234
}
235235

236+
lock.SetIgnoreShellMismatch(true)
236237
env, err := d.ensureStateIsUpToDateAndComputeEnv(ctx)
237238
if err != nil {
238239
return err

internal/lock/statehash.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"go.jetpack.io/devbox/internal/cuecfg"
1414
)
1515

16+
var ignoreShellMismatch = false
17+
1618
// stateHashFile is a non-shared lock file that helps track the state of the
1719
// local devbox environment. It contains hashes that may not be the same across
1820
// machines (e.g. manifest hash).
@@ -46,6 +48,12 @@ func UpdateAndSaveStateHashFile(args UpdateStateHashFileArgs) error {
4648
return cuecfg.WriteFile(stateHashFilePath(args.ProjectDir), newLock)
4749
}
4850

51+
// SetIgnoreShellMismatch is used to disable the shell comparison when checking
52+
// if the state is up to date. This is useful when we don't load shellrc (e.g. running)
53+
func SetIgnoreShellMismatch(ignore bool) {
54+
ignoreShellMismatch = ignore
55+
}
56+
4957
func isStateUpToDate(args UpdateStateHashFileArgs) (bool, error) {
5058
filesystemStateHash, err := readStateHashFile(args.ProjectDir)
5159
if err != nil {
@@ -56,6 +64,10 @@ func isStateUpToDate(args UpdateStateHashFileArgs) (bool, error) {
5664
return false, err
5765
}
5866

67+
if ignoreShellMismatch {
68+
filesystemStateHash.IsFish = newStateHash.IsFish
69+
}
70+
5971
return *filesystemStateHash == *newStateHash, nil
6072
}
6173

0 commit comments

Comments
 (0)