@@ -41,6 +41,30 @@ type SyncMapping struct {
4141 Prefix string `json:"prefix"`
4242 Remote string `json:"remote"`
4343 Direction SyncDirection `json:"direction,omitempty"`
44+ // LFS, when true, configures the synced shadow clone to track
45+ // the patterns in LFSPatterns via git-lfs. Useful when binary
46+ // assets (uploaded via the image-support tools) would otherwise
47+ // balloon the git repo. Requires git-lfs on the host. Defaults
48+ // off because GitHub wikis don't support LFS — flip it on only
49+ // for plain repos / providers that do.
50+ LFS bool `json:"lfs,omitempty"`
51+ // LFSPatterns is the list of .gitattributes patterns to route
52+ // through LFS. If empty when LFS is true, a sensible default
53+ // (the browser-renderable image extensions plus .pdf) is used
54+ // — see DefaultLFSPatterns.
55+ LFSPatterns []string `json:"lfs_patterns,omitempty"`
56+ }
57+
58+ // DefaultLFSPatterns returns the default set of file patterns to route
59+ // through LFS when a sync mapping enables LFS but doesn't override the
60+ // patterns explicitly. Tracks the browser-renderable image set used by
61+ // the upload tools, plus common companion formats agents are likely to
62+ // reach for next.
63+ func DefaultLFSPatterns () []string {
64+ return []string {
65+ "*.png" , "*.jpg" , "*.jpeg" , "*.gif" , "*.webp" ,
66+ "*.avif" , "*.svg" , "*.bmp" , "*.ico" ,
67+ }
4468}
4569
4670// SyncConfig holds git sync settings.
@@ -90,7 +114,8 @@ func (s *SyncConfig) ResolveRemote(pagePath string) string {
90114// If a mapping for prefix already exists, its remote and direction are
91115// both replaced — this is treated as a re-registration, not an additive
92116// op, so an existing mapping switching from bidirectional to pull-only
93- // (or vice versa) propagates cleanly.
117+ // (or vice versa) propagates cleanly. LFS settings on an existing
118+ // mapping are preserved; use AddMappingWithLFS to update them.
94119func (s * SyncConfig ) AddMapping (prefix , remote string , direction SyncDirection ) {
95120 direction = direction .Normalize ()
96121 for i , m := range s .Mappings {
@@ -103,6 +128,34 @@ func (s *SyncConfig) AddMapping(prefix, remote string, direction SyncDirection)
103128 s .Mappings = append (s .Mappings , SyncMapping {Prefix : prefix , Remote : remote , Direction : direction })
104129}
105130
131+ // AddMappingWithLFS is like AddMapping but also sets the LFS flag and
132+ // (optionally) the LFS patterns. Patterns default to DefaultLFSPatterns
133+ // when LFS is true and patterns is nil. Pass an empty (non-nil) slice
134+ // to explicitly track nothing — that's a usable no-op state for an
135+ // operator who wants to flip LFS on later.
136+ func (s * SyncConfig ) AddMappingWithLFS (prefix , remote string , direction SyncDirection , lfs bool , patterns []string ) {
137+ direction = direction .Normalize ()
138+ if lfs && patterns == nil {
139+ patterns = DefaultLFSPatterns ()
140+ }
141+ for i , m := range s .Mappings {
142+ if m .Prefix == prefix {
143+ s .Mappings [i ].Remote = remote
144+ s .Mappings [i ].Direction = direction
145+ s .Mappings [i ].LFS = lfs
146+ s .Mappings [i ].LFSPatterns = patterns
147+ return
148+ }
149+ }
150+ s .Mappings = append (s .Mappings , SyncMapping {
151+ Prefix : prefix ,
152+ Remote : remote ,
153+ Direction : direction ,
154+ LFS : lfs ,
155+ LFSPatterns : patterns ,
156+ })
157+ }
158+
106159// Remotes returns all unique remotes (default + mappings).
107160func (s * SyncConfig ) Remotes () []string {
108161 seen := make (map [string ]bool )
0 commit comments