My Perforce-based project supports both Linux and Cygwin platforms with the same shell scripts (e.g. build_project.sh
). But Perforce defaults line endings for text files to the local platform (Docs). This causes \r\n
newlines in the .sh
scripts, which fail on Cygwin.
Some of the ideas I've thought of so far:
Is there a way to make Cygwin accept \r\n files? (Without having to run
dos2unix
, the files fetch as read-only).Is there a way to set specific files to be text, but with Unix line endings for everyone? (I am guessing, "no", but thought I'd check.)
Of course I can set the entire workspace's line endings to
\n
(unix). But this makes the Windows clients unhappy with their.bat
files being\n
instead of\r\n
. Also if the setting is per workspace (I can't recall), then a workspace setup is slightly harder for the new Windows user as they must set that option.Set the
.sh
files to be "binary", but then we lose the text diffs on those files. Is there a workaround for this? Is this the common (good) hack?
This is a fairly minor nit, but I suspect that some of you have a BKM for this pattern.
Thanks.
EDIT: Craig's answer in this question seems to suggest that using Unix line endings will just leave files with \r\n
's alone if they are originally submitted that way.
EDIT: To force bash (i.e. Cygwin) to accept files with \r\n
endings, one can specify set -o igncr
in the script. This is nice if one expects Cygwin users to that might not be very Unix literate (my case) or when we can't globally impose the trigger in the solution below for some other reason.