(* Copyright (c) 2024-2026 Thomas Gazagnaire Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. *) (** Git attributes (gitattributes(5)). Parses [gitattributes(5)] lines ([ attr1 attr2 ...] and [[attr] attr1 ...]) and resolves the state of any attribute for a path, as [git check-attr] does, then the [text], [eol] and [merge] attributes the work tree and a merge read. Patterns use the same syntax as [.gitignore] (see {!Pathspec}). *) type t (** A set of attribute rules, in declaration order. *) val pp : Format.formatter -> t -> unit (** [pp ppf t] prints an unspecified representation of [t] on [ppf]. *) val empty : t (** [empty] sets no attributes. *) val of_file_content : base:string -> string -> t (** [of_file_content ~base content] is the rules of one attributes file. [base] is the directory of the file, slash-separated and relative to the work-tree root ([""] for the root). *) val append : t -> t -> t (** [append a b] is the rules of [a] followed by those of [b]. For each attribute the last matching rule wins, so [b] overrides [a], as a nested file overrides its parents. *) (** {1:states Any attribute} *) (** The type for the state of an attribute for a path. *) type state = | Set (** [name]: the attribute is set. *) | Unset (** [-name]: the attribute is unset. *) | Value of string (** [name=value]: the attribute holds [value]. *) | Unspecified (** No rule gives the attribute a state, or [!name] took it away. *) val check : t -> path:string -> string -> state (** [check t ~path name] is the state of attribute [name] for the file [path], as [git check-attr name -- path] reports it. *) val of_dirs : read:(string -> string option) -> string -> t (** [of_dirs ~read dir] is the rules in force in the directory [dir]: those of the [.gitattributes] file of the root and then of each directory down to [dir], [read d] being the content of [d/.gitattributes] if there is one ([d] is slash-separated, [""] for the root). *) (** {1:eol End of line and merge} *) (** The type for the [core.autocrlf] setting, used when no [text] or [eol] attribute applies. *) type autocrlf = True | Input | False val normalizes_eol : t -> autocrlf:autocrlf -> path:string -> content:string -> bool (** [normalizes_eol t ~autocrlf ~path ~content] is [true] iff git converts CRLF to LF when it hashes the work-tree file [path], the clean filter of text files. [content] is the raw content of the file, which decides whether it is binary under [text=auto] and [core.autocrlf]. *) (** The type for the [merge] attribute: how a three-way merge combines a file that both sides changed (gitattributes(5), "Performing a three-way merge"). *) type merge_driver = | Text_merge (** [merge], [merge=text], [!merge] or unspecified: the line-based three-way merge. *) | Binary_merge (** [-merge], [merge=binary] or the [binary] macro: ours is kept and the path conflicts. *) | Union_merge (** [merge=union]: the lines of both sides, with no conflict. *) | Driver of string (** [merge=name] for any other [name]: a driver that git's [merge..driver] configuration defines. *) val merge_driver : t -> path:string -> merge_driver (** [merge_driver t ~path] is the [merge] attribute of [path], the last matching rule winning. An unspecified attribute is {!constructor-Text_merge}: the [merge.default] configuration is not read. *)