[p4ruby] fix for symlink-in-PWD problem

bob p4 jeffperforce at gmail.com
Thu Mar 6 06:29:24 PST 2008

[ In reference to
http://maillist.perforce.com/pipermail/p4ruby/2008q1/000115.html ]

I finally got P4Win cooperating with cygwin-p4ruby via listing my
cygwin path in AltRoots, however I ran into a bit of confusion along
the way.  My client root is /home/me/some/long/path, which I have
symlinked to /home/me/work.  Apparently this causes a glitch since the
shell sets PWD to /home/me/work instead of the full path:


Note the Perforce authors decided not to solve the problem: "However,
this doesn't necessarily fix the issue of symlinks under the Perforce
client root. For that, you will still need to either set and export
the $PWD environment variable, or use the -d argument as necessary."

May I suggest the following patch to workaround it:

require 'p4'
require 'pathname'

class P4
   class << self
      alias_method :previous_new, :new
      def new(*args, &block)
         previous_pwd = ENV["PWD"]
            ENV["PWD"] = Pathname.new(previous_pwd).realpath
            previous_new(*args, &block)
            ENV["PWD"] = previous_pwd

I am using p4ruby-2007.3 with cygwin p4api-2007.3.143793.

IMO Perforce should expand away the symlink, but until then at least
P4Ruby can do it.  Please spare others from this needless pain!

More information about the p4ruby mailing list