Saturday, November 17, 2012

Avoiding Perl Locale Errors with Remote Git

I've long been troubled with annoying locale warnings that I got with every Git command.

$ git pull
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "fi_FI.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Current branch master is up to date.

Generating the locales with "locale-gen fi_FI fi_FI.UTF-8", which was suggested by some, didn't help at all.

It seems that the problem occurs with remote SSH repositories, when Git makes an SSH call to the server. Apparently, it runs a shell in the remote host. It forwards language environment variables to the remote host, but when the remote host doesn't have the locale installed, the error occurs.

So, the solutions are:

  1. generate the locales in the remote repository server, or if that is not possible,
  2. change the locale to LANG=C in the local host.

I prefer to have the fi_FI as my system locale, so I wrapped the git calls in the following Bash script:

#!/bin/bash

# This is needed when git makes an SSH call to a remote
# server which doesn't have # all the locales installed
export LANG=C

# Note: the "$@" is important notation to avoid
# splitting arguments at spaces
/usr/bin/git "$@"

3 comments:

Dan Scott said...

Thanks for the tip!

One note, in my experience I had to export LC_ALL rather than LANG to make the remote server happy.

Marko Grönroos said...

Yes, I also noticed on another machine that other locale variables may need to be modified instead or as well.

Nicolas said...

Nicce post