janet-lang / jpm

Janet Project Manager
MIT License
68 stars 22 forks source link

`jpm install` throws error if the project doesn't have a Git repo #39

Closed paulsnar closed 2 years ago

paulsnar commented 2 years ago

Manifest generation shells out to Git to get the remote URL and the current commit hash:

https://github.com/janet-lang/jpm/blob/5dd1ab7780eeb967dc7fad8e9af3d071f50e6fca/jpm/declare.janet#L320-L323

If this is performed for a project which doesn't have a Git repo, Git exits with status code 128 and an error message about .git being nonexistent:

pnlib/ $ jpm install
generating ~/.local/lib/janet/.manifests/pnlib.jdn...
fatal: not a git repository (or any of the parent directories): .git
error: command failed with non-zero exit code 128
  in os/proc-wait [src/core/os.c] on line 529
  in exec-slurp [~/.local/lib/janet/jpm/shutil.janet] on line 125, column 3
  in <anonymous> [~/.local/lib/janet/jpm/declare.janet] on line 320, column 24
  in <anonymous> [~/.local/lib/janet/jpm/rules.janet] on line 18, column 20
  in executor [~/.local/lib/janet/jpm/rules.janet] on line 25, column 8
  in worker [~/.local/lib/janet/jpm/dagbuild.janet] on line 65, column 23
  in <anonymous> [~/.local/lib/janet/jpm/dagbuild.janet] on line 21, column 43
  in pmap [~/.local/lib/janet/jpm/dagbuild.janet] on line 26, column 7
  in pdag [~/.local/lib/janet/jpm/dagbuild.janet] (tailcall) on line 71, column 3
  in _thunk [~/.local/bin/jpm] (tailcall) on line -1, column -1
  in cli-main [boot.janet] on line 3644, column 17

Given that ff61f1ada74626fdd8aa95a360ca0a1b7ba0223e changed how process slurping works, this basically boils down to the :x flag being passed to os/spawn here:

https://github.com/janet-lang/jpm/blob/ff61f1ada74626fdd8aa95a360ca0a1b7ba0223e/jpm/shutil.janet#L119

If this is removed and nil is returned from exec-slurp on non-zero exit code, all is well. I've made a basic patch at https://github.com/paulsnar/janet-jpm/commit/3e31f2df6638fd5851ec2eedd9f1eaba11be549a that does just that, though it's maybe not the cleanest approach (perhaps stderr could be swallowed too in this case.)

bakpakin commented 2 years ago

This should only happen if the bundle type is git, which makes sense. A better solution is to simply avoid this code path if a .git directory is not present for a project - we can just check for .git or something similar.

paulsnar commented 2 years ago

That does indeed work better, thanks!