-
Notifications
You must be signed in to change notification settings - Fork 280
Closed
Labels
Description
I'm running overcommit within a docker container and the pre-commit always outputs:
error: process ID out of range
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
This is because the pre-commit checks if the parent process has the '--amend' flag on his command line. But when run inside docker the command will have no parent process at all.
In this case:
irb(main):001:0> Process.ppid
=> 0
Then ps system command will fail at:
overcommit/lib/overcommit/utils.rb
Line 146 in 764d9a1
| `ps -ocommand= -p #{Process.ppid}`.chomp |
The Overcommit::Utils.parent_command method should be extended to handle the case when there is no parent (ppid=0) or when the ps command fails with a non-zero return code.
Possible solution may be:
def parent_command
return if Process.ppid.zero?
output = if OS.windows?
`wmic process where ProcessId=#{Process.ppid} get CommandLine /FORMAT:VALUE`.
strip.
slice(/(?<=CommandLine=).+/)
elsif OS.cygwin?
# Cygwin's `ps` command behaves differently than the traditional
# Linux version, but a comparable `procps` is provided to compensate.
`procps -ocommand= -p #{Process.ppid}`.chomp
else
`ps -ocommand= -p #{Process.ppid}`.chomp
end
return unless $?.success?
output
end