Skip to content

Commit

Permalink
chore(volta): Make volta_deactivate.sh more portable
Browse files Browse the repository at this point in the history
### Issues addressed
I've been getting an issue locally when running volta via lefthook.
Specifically, I'd see an error like this:

```
$ git commit -am Test
.git/hooks/post-checkout: 13: /home/topher/miniforge3/envs/memfault/etc/conda/deactivate.d/volta_deactivate.sh: Bad substitution
ERROR: Command failed with error exit code 1:
```

I tracked the issue down to non-portable bash-specific handling.

### Summary of changes
I _think_ adding the shebang (`#!/bin/bash`) _should_ have been
sufficient here to get my local machine working, however this had no
impact.

I'm not going to spend a ton of time debugging this; I re-wrote it to be
more portable and avoid the problematic field.

### Test Plan
- [x] I can now run `git commit` without error
  • Loading branch information
topher200 committed Oct 8, 2024
1 parent c435ee2 commit fa6c212
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions volta/deactivate.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#!/bin/bash

# if VOLTA_HOME_PREFERRED is set, don't unset VOLTA_HOME; the user activated the
# conda environment with VOLTA_HOME already set, and we don't want to mess with
# it
if [ -n "$VOLTA_HOME_PREFERRED" ]; then
unset VOLTA_HOME_PREFERRED
else
# otherwise, clean up after ourselves
# remove the directory from PATH
directory_to_remove=$VOLTA_HOME/bin
# from https://unix.stackexchange.com/a/108933
PATH=:$PATH:
PATH=${PATH//:$directory_to_remove:/:}
PATH=${PATH#:}
PATH=${PATH%:}
new_path=""
old_ifs=$IFS
IFS=":"
for dir in $PATH; do
if [ "$dir" != "$directory_to_remove" ]; then
new_path="$new_path:$dir"
fi
done
IFS=$old_ifs

# Remove the leading colon if necessary
PATH=${new_path#:}

unset VOLTA_HOME
fi
2 changes: 1 addition & 1 deletion volta/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package:
name: {{ name }}
version: {{ version }}.memfault2
version: {{ version }}.memfault3

source:
# bash for getting the sigs:
Expand Down

0 comments on commit fa6c212

Please sign in to comment.