# eol

Contents

- Description

automatically manage newlines in repository files

# Description

This extension allows you to manage the type of line endings (CRLF or LF) that are used in the repository and in the local working directory. That way you can get CRLF line endings on Windows and LF on Unix/Mac, thereby letting everybody use their OS native line endings.

The extension reads its configuration from a versioned `.hgeol` configuration file found in the root of the working directory. The `.hgeol` file use the same syntax as all other Mercurial configuration files. It uses two sections, `[patterns]` and `[repository]`.

The `[patterns]` section specifies how line endings should be converted between the working directory and the repository. The format is specified by a file pattern. The first match is used, so put more specific patterns first. The available line endings are `LF`, `CRLF`, and `BIN`.

Files with the declared format of `CRLF` or `LF` are always checked out and stored in the repository in that format and files declared to be binary (`BIN`) are left unchanged. Additionally, `native` is an alias for checking out in the platform's default line ending: `LF` on Unix (including Mac OS X) and `CRLF` on Windows. Note that `BIN` (do nothing to line endings) is Mercurial's default behavior; it is only needed if you need to override a later, more general pattern.

The optional `[repository]` section specifies the line endings to use for files stored in the repository. It has a single setting, `native`, which determines the storage line endings for files declared as `native` in the `[patterns]` section. It can be set to `LF` or `CRLF`. The default is `LF`. For example, this means that on Windows, files configured as `native` (`CRLF` by default) will be converted to `LF` when stored in the repository. Files declared as `LF`, `CRLF`, or `BIN` in the `[patterns]` section are always stored as-is in the repository.

Example versioned `.hgeol` file:

    [patterns]
    **.py = native
    **.vcproj = CRLF
    **.txt = native
    Makefile = LF
    **.jpg = BIN

    [repository]
    native = LF

Note

The rules will first apply when files are touched in the working directory, e.g. by updating to null and back to tip to touch all files.

The extension uses an optional `[eol]` section read from both the normal Mercurial configuration files and the `.hgeol` file, with the latter overriding the former. You can use that section to control the overall behavior. There are three settings:

- `eol.native` (default `os.linesep`) can be set to `LF` or `CRLF` to override the default interpretation of `native` for checkout. This can be used with `hg archive` on Unix, say, to generate an archive where files have line endings for Windows.
- `eol.only-consistent` (default True) can be set to False to make the extension convert files with inconsistent EOLs. Inconsistent means that there is both `CRLF` and `LF` present in the file. Such files are normally not touched under the assumption that they have mixed EOLs on purpose.
- `eol.fix-trailing-newline` (default False) can be set to True to ensure that converted files end with a EOL character (either `\n` or `\r\n` as per the configured patterns).

The extension provides `cleverencode:` and `cleverdecode:` filters like the deprecated win32text extension does. This means that you can disable win32text and enable eol and your filters will still work. You only need to these filters until you have prepared a `.hgeol` file.

The `win32text.forbid*` hooks provided by the win32text extension have been unified into a single hook named `eol.checkheadshook`. The hook will lookup the expected line endings from the `.hgeol` file, which means you must migrate to a `.hgeol` file first before using the hook. `eol.checkheadshook` only checks heads, intermediate invalid revisions will be pushed. To forbid them completely, use the `eol.checkallhook` hook. These hooks are best used as `pretxnchangegroup` hooks.

See `hg help patterns` for more information about the glob patterns used.