Skip to content

Commit

Permalink
Merge pull request #621 from adrianna-chang-shopify/spring-process-sh…
Browse files Browse the repository at this point in the history
…ould-use-working-dir

Start Spring server process in directory where command was called
  • Loading branch information
tenderlove authored Jul 23, 2020
2 parents 647b8c3 + 7abf456 commit c9716c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Next Release

* Start server process in directory where command was called

## 2.1.0

* Add explicit support for Rails 6 (no changes were needed)
Expand Down
6 changes: 6 additions & 0 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def serve(client)
end
end

# Ensure we boot the process in the directory the command was called from,
# not from the directory Spring started in
original_dir = Dir.pwd
Dir.chdir(env['PWD'] || original_dir)

pid = fork {
Process.setsid
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
Expand Down Expand Up @@ -237,6 +242,7 @@ def serve(client)
# (i.e. to prevent `spring rake -T | grep db` from hanging forever),
# even when exception is raised before forking (i.e. preloading).
reset_streams
Dir.chdir(original_dir)
end

def terminate
Expand Down

0 comments on commit c9716c2

Please sign in to comment.