Skip to content

fix(activate): export __MISE_EXE and resolve bare ARGV0 to absolute path#9081

Merged
jdx merged 2 commits intojdx:mainfrom
fru1tworld:fix/bash-export-mise-exe
Apr 15, 2026
Merged

fix(activate): export __MISE_EXE and resolve bare ARGV0 to absolute path#9081
jdx merged 2 commits intojdx:mainfrom
fru1tworld:fix/bash-export-mise-exe

Conversation

@fru1tworld
Copy link
Copy Markdown
Contributor

Refs #8984

__MISE_EXE was not exported in bash activate, so child shells couldn't access it and the mise function failed. Additionally on Linux, when ARGV0 is a bare name (e.g. mise) instead of an absolute path, PATH changes could break execution.

  • add export to __MISE_EXE= in activate.sh
  • resolve bare ARGV0 via which::which, falling back to MISE_BIN

Verification:

  • mise run lint-fix
  • mise run test:unit (629 passed)
  • mise run test:e2e test_activate_export

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the bash activation script to export the __MISE_EXE environment variable and refines the logic for resolving the executable path on Linux to prefer absolute paths. A review comment points out that relative paths containing separators, such as ./mise, are not currently transformed into absolute paths, which could cause issues if the working directory is changed after activation. The reviewer provided a code snippet to resolve this by joining such paths with the current working directory.

Comment thread src/cli/activate.rs
Comment on lines +78 to +83
let argv0 = PathBuf::from(&*env::ARGV0);
if argv0.is_absolute() {
argv0
} else {
which::which(&*env::ARGV0).unwrap_or_else(|_| env::MISE_BIN.clone())
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation correctly resolves bare names (e.g., mise) to absolute paths using which. However, if ARGV0 is a relative path with a separator (e.g., ./mise), which returns it as-is, leaving mise_bin relative. This can cause the mise function to fail if the user changes their current working directory after activation. To ensure __MISE_EXE is always absolute (as expected by the tests and for robustness), relative paths should be joined with the current working directory to make them absolute without resolving symlinks.

            let argv0 = PathBuf::from(&*env::ARGV0);
            let path = if argv0.is_absolute() {
                argv0
            } else {
                which::which(&*env::ARGV0).unwrap_or_else(|_| env::MISE_BIN.clone())
            };
            if path.is_absolute() {
                path
            } else {
                std::env::current_dir()
                    .map(|cwd| cwd.join(path))
                    .unwrap_or_else(|_| env::MISE_BIN.clone())
            }

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 14, 2026

Greptile Summary

This PR fixes two related bugs in mise activate bash: __MISE_EXE was not exported so child shells couldn't access it, and on Linux a bare ARGV0 (e.g. mise) without an absolute path could break if PATH changed after activation. The fix adds export to activate.sh and resolves bare ARGV0 via which::which with a current_dir join fallback before defaulting to MISE_BIN.

Confidence Score: 5/5

This PR is safe to merge; both fixes are minimal, correct, and well-tested.

All findings are P2 or lower (edge cases already acknowledged in prior thread comments). The primary bug fix (export + bare ARGV0 resolution) is straightforward and the unit/e2e test suite passes.

No files require special attention.

Important Files Changed

Filename Overview
src/assets/bash/activate.sh Adds export to __MISE_EXE so the variable is visible in child shells; a minimal, correct one-line fix.
src/cli/activate.rs Resolves bare ARGV0 to absolute path via which::which on Linux, with current_dir join and MISE_BIN fallback; logic is sound for the primary use case.
e2e/cli/test_activate_export New E2E test verifying export __MISE_EXE= is present, path is absolute, and child shell inherits the variable; assertions 1 and 2 are robust, assertion 3's eval scope is a minor style concern already noted.
src/shell/snapshots/mise__shell__bash__tests__activate.snap Snapshot correctly updated to reflect the new export __MISE_EXE= prefix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["mise activate bash (Linux)"] --> B{"ARGV0 is absolute?"}
    B -- Yes --> E["Use ARGV0 as mise_bin"]
    B -- No --> C["which::which(ARGV0)"]
    C -- Success --> D{"Result is absolute?"}
    C -- Failure --> F["Fallback: MISE_BIN (current_exe)"]
    D -- Yes --> E
    D -- No --> G["current_dir().join(path)"]
    G -- Success --> E
    G -- Failure --> F
    E --> H["Embed as export __MISE_EXE=<mise_bin> in activate.sh"]
    F --> H
    H --> I["Child shell inherits __MISE_EXE via export"]
Loading

Reviews (2): Last reviewed commit: "fix(activate): resolve relative ARGV0 pa..." | Re-trigger Greptile

Comment thread src/cli/activate.rs
Comment on lines +12 to +13
eval "$(mise activate bash --no-hook-env)"
assert "bash -c 'echo \$__MISE_EXE'" "$__MISE_EXE"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test assertion 3 uses eval in test shell scope

eval "$(mise activate bash --no-hook-env)" modifies the current test shell's environment (defines mise(), _mise_hook, etc., and calls _mise_hook immediately). If _mise_hook fails or produces unexpected output, it could affect the assert below it. Consider sourcing into a subshell or just relying on assertions 1 and 2 (which already prove the export is present) to keep the test scope cleaner.

@fru1tworld
Copy link
Copy Markdown
Contributor Author

Addressed the relative path edge case — which result is now joined with current_dir() when non-absolute.

@jdx jdx merged commit bf802ac into jdx:main Apr 15, 2026
34 checks passed
mise-en-dev added a commit that referenced this pull request Apr 15, 2026
### 🚀 Features

- **(npm)** use --min-release-age for npm 11.10.0+ supply chain
protection by @webkaz in [#9072](#9072)
- **(registry)** add openfga by @mnm364 in
[#9084](#9084)
- **(task)** allow to set confirmation default by @roele in
[#9089](#9089)
- support os/arch compound syntax in tool os filtering by @RobertDeRose
in [#9088](#9088)

### 🐛 Bug Fixes

- **(activate)** export __MISE_EXE and resolve bare ARGV0 to absolute
path by @fru1tworld in [#9081](#9081)
- **(install)** support aliased installs sharing a backend by @jdx in
[#9093](#9093)
- **(shim)** use which_no_shims when resolving mise binary in reshim and
doctor by @kevinswiber in [#9071](#9071)
- filter empty segments in colon-separated env var parsing by @baby-joel
in [#9076](#9076)

### 📚 Documentation

- fix wrong file reference to forgejo backend implemenation by @roele in
[#9090](#9090)
- fix cli token command for token resolution by @roele in
[#9077](#9077)

### 📦 Registry

- add trzsz-go
([aqua:trzsz/trzsz-go](https://github.com/trzsz/trzsz-go)) by
@ZeroAurora in [#9083](#9083)
- add copilot
([aqua:github/copilot-cli](https://github.com/github/copilot-cli)) by
@risu729 in [#9082](#9082)

### Chore

- add AGENTS.md symlink by @jdx in
[#9094](#9094)

### New Contributors

- @kevinswiber made their first contribution in
[#9071](#9071)
- @webkaz made their first contribution in
[#9072](#9072)
- @RobertDeRose made their first contribution in
[#9088](#9088)

## 📦 Aqua Registry Updates

#### New Packages (7)

-
[`IBM-Cloud/ibm-cloud-cli-release`](https://github.com/IBM-Cloud/ibm-cloud-cli-release)
- [`max-sixty/worktrunk`](https://github.com/max-sixty/worktrunk)
- [`micelio.dev/hif`](https://github.com/micelio.dev/hif)
- [`pgplex/pgschema`](https://github.com/pgplex/pgschema)
-
[`rose-pine/rose-pine-bloom`](https://github.com/rose-pine/rose-pine-bloom)
- [`santosr2/TerraTidy`](https://github.com/santosr2/TerraTidy)
- [`trzsz/trzsz-go`](https://github.com/trzsz/trzsz-go)

#### Updated Packages (3)

- [`mvdan/sh`](https://github.com/mvdan/sh)
- [`rvben/rumdl`](https://github.com/rvben/rumdl)
- [`temporalio/temporal`](https://github.com/temporalio/temporal)
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Apr 16, 2026
## [2026.4.14](https://github.com/jdx/mise/compare/v2026.4.13..v2026.4.14) - 2026-04-15

### Chore

- bump sigstore-verification by @jdx in [#9128](jdx/mise#9128)

## [2026.4.13](https://github.com/jdx/mise/compare/v2026.4.12..v2026.4.13) - 2026-04-15

### 🐛 Bug Fixes

- **(go)** honor install_before for module versions by @mariusvniekerk in [#9097](jdx/mise#9097)
- **(vfox-plugin)** support Git URL with commit hash for mise.toml by @Oyami-Srk in [#9099](jdx/mise#9099)
- `MISE_FETCH_REMOTE_VERSIONS_CACHE` not respected by @mcncl in [#9096](jdx/mise#9096)

### 📦️ Dependency Updates

- unblock cargo-deny advisories check by @jdx in [#9112](jdx/mise#9112)

### New Contributors

- @mariusvniekerk made their first contribution in [#9097](jdx/mise#9097)
- @mcncl made their first contribution in [#9096](jdx/mise#9096)
- @Oyami-Srk made their first contribution in [#9099](jdx/mise#9099)

## [2026.4.12](https://github.com/jdx/mise/compare/v2026.4.11..v2026.4.12) - 2026-04-15

### 🚀 Features

- **(npm)** use --min-release-age for npm 11.10.0+ supply chain protection by @webkaz in [#9072](jdx/mise#9072)
- **(registry)** add openfga by @mnm364 in [#9084](jdx/mise#9084)
- **(task)** allow to set confirmation default by @roele in [#9089](jdx/mise#9089)
- support os/arch compound syntax in tool os filtering by @RobertDeRose in [#9088](jdx/mise#9088)

### 🐛 Bug Fixes

- **(activate)** export __MISE_EXE and resolve bare ARGV0 to absolute path by @fru1tworld in [#9081](jdx/mise#9081)
- **(install)** support aliased installs sharing a backend by @jdx in [#9093](jdx/mise#9093)
- **(shim)** use which_no_shims when resolving mise binary in reshim and doctor by @kevinswiber in [#9071](jdx/mise#9071)
- filter empty segments in colon-separated env var parsing by @baby-joel in [#9076](jdx/mise#9076)

### 📚 Documentation

- fix wrong file reference to forgejo backend implemenation by @roele in [#9090](jdx/mise#9090)
- fix cli token command for token resolution by @roele in [#9077](jdx/mise#9077)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants