Skip to content

gitattributes.star

Set attributes for path patterns in .gitattributes, such as line endings and Git LFS tracking.

load("@fleet//gitattributes.star", "set", "track_lfs")
Function What it does
set Gives a pattern attributes, merging with any it already has.
track_lfs Tracks a pattern with Git LFS, as git lfs track would.

set

set(repo, pattern, attributes)

Gives a pattern attributes, merging with any it already has.

An attribute already on the pattern's line is replaced by the new one with the same name, so eol=crlf becomes eol=lf and text becomes -text; other attributes stay. A pattern with no line gets one at the end. The file is created if needed.

Arguments

Name Description
repo The repo passed to change(repo).
pattern The path pattern, such as *.sh or *.
attributes The attributes, as a space-separated string or a list, such as "text eol=lf".

Returns: True when the file changed.

Example

set(repo, "*.sh", "eol=lf")
set(repo, "*.png", "binary")
# returns True

.gitattributes

* text=auto
*.sh text eol=crlf

.gitattributes

* text=auto
*.sh text eol=lf
*.png binary

Used in: editor-defaults

Source

track_lfs

track_lfs(repo, pattern)

Tracks a pattern with Git LFS, as git lfs track would.

This only edits .gitattributes; files already committed stay in Git until they are migrated.

Arguments

Name Description
repo The repo passed to change(repo).
pattern The path pattern, such as *.psd.

Returns: True when the file changed.

Example

track_lfs(repo, "*.psd")
# returns True

.gitattributes

* text=auto

.gitattributes

* text=auto
*.psd filter=lfs diff=lfs merge=lfs -text

Source