Skip to content

Start Spring server process in directory where command was called #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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