| 1 | package commandsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/ |
| 2 | |
| 3 | import ( |
| 4 | "bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/" |
| 5 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 6 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 9 | "pathscip-go gomod github.com/golang/go/src go1.25.0 path/" |
| 10 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 11 | "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/" |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 13 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 14 | |
| 15 | "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/" |
| 16 | "github.com/git-lfs/git-lfs/v3/git/gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/" |
| 17 | "github.com/git-lfs/git-lfs/v3/toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/" |
| 18 | "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/" |
| 19 | "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/" |
| 20 | ) |
| 21 | |
| 22 | var ( |
| 23 | prefixBlocklistscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prefixBlocklist. = []string{ |
| 24 | ".git", ".lfs", |
| 25 | } |
| 26 | |
| 27 | trackLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackLockableFlag. bool |
| 28 | trackNotLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNotLockableFlag. bool |
| 29 | trackVerboseLoggingFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackVerboseLoggingFlag. bool |
| 30 | trackDryRunFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackDryRunFlag. bool |
| 31 | trackNoModifyAttrsFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoModifyAttrsFlag. bool |
| 32 | trackNoExcludedFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoExcludedFlag. bool |
| 33 | trackFilenameFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackFilenameFlag. bool |
| 34 | trackJSONFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackJSONFlag. bool |
| 35 | ) |
| 36 | |
| 37 | func trackCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackCommand().(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#, args []string) { |
| 38 | requireGitVersionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/requireGitVersion().() |
| 39 | setupWorkingCopyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/setupWorkingCopy().() |
| 40 | |
| 41 | if trackDryRunFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackDryRunFlag. { |
| 42 | trackNoModifyAttrsFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoModifyAttrsFlag. = true |
| 43 | } |
| 44 | |
| 45 | if !cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Osscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Os..Boolscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Bool.("GIT_LFS_TRACK_NO_INSTALL_HOOKS", false) { |
| 46 | installHooksscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/installHooks().(false) |
| 47 | } |
| 48 | |
| 49 | if len(args) == 0 { |
| 50 | listPatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/listPatterns().() |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | if trackJSONFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackJSONFlag. { |
| 55 | Exitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Exit().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("--json option can't be combined with arguments")) |
| 56 | } |
| 57 | |
| 58 | mp := gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.NewMacroProcessorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/NewMacroProcessor().() |
| 59 | |
| 60 | // Intentionally do _not_ consider global- and system-level |
| 61 | // .gitattributes here. Parse them still to expand any macros. |
| 62 | gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.GetSystemAttributePathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/GetSystemAttributePaths().(mp, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Osscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Os.) |
| 63 | gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.GetUserAttributePathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/GetUserAttributePaths().(mp, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Git.) |
| 64 | knownPatterns := gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.GetAttributePathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/GetAttributePaths().(mp, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..LocalWorkingDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#LocalWorkingDir().(), cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..LocalGitDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#LocalGitDir().()) |
| 65 | lineEnd := getAttributeLineEndingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/getAttributeLineEnding().(knownPatterns) |
| 66 | if len(lineEnd) == 0 { |
| 67 | lineEnd = gitLineEndingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/gitLineEnding().(cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Git.) |
| 68 | } |
| 69 | |
| 70 | wd, _ := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.Getwdscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/Getwd().() |
| 71 | wd = toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.ResolveSymlinksscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ResolveSymlinks().(wd) |
| 72 | relpath, err := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Relscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Rel().(cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..LocalWorkingDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#LocalWorkingDir().(), wd) |
| 73 | if err != nil { |
| 74 | Exitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Exit().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Current directory %q outside of Git working directory %q.", wd, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..LocalWorkingDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#LocalWorkingDir().())) |
| 75 | } |
| 76 | |
| 77 | changedAttribLines := make(map[string]string) |
| 78 | var readOnlyPatterns []string |
| 79 | var writeablePatterns []string |
| 80 | ArgsLoop: |
| 81 | for _, unsanitizedPattern := range args { |
| 82 | pattern := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.TrimCurrentPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TrimCurrentPrefix().(cleanRootPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cleanRootPath().(unsanitizedPattern)) |
| 83 | |
| 84 | // Generate the new / changed attrib line for merging |
| 85 | var encodedArg string |
| 86 | if trackFilenameFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackFilenameFlag. { |
| 87 | encodedArg = escapeGlobCharactersscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/escapeGlobCharacters().(pattern) |
| 88 | pattern = escapeGlobCharactersscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/escapeGlobCharacters().(pattern) |
| 89 | } else { |
| 90 | encodedArg = escapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/escapeAttrPattern().(pattern) |
| 91 | } |
| 92 | |
| 93 | if !trackNoModifyAttrsFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoModifyAttrsFlag. { |
| 94 | for _, known := range knownPatterns { |
| 95 | if unescapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/unescapeAttrPattern().(known.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Path.) == pathscip-go gomod github.com/golang/go/src go1.25.0 path/.Joinscip-go gomod github.com/golang/go/src go1.25.0 path/Join().(relpath, pattern) && |
| 96 | ((trackLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackLockableFlag. && known.Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Lockable.) || // enabling lockable & already lockable (no change) |
| 97 | (trackNotLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNotLockableFlag. && !known.Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Lockable.) || // disabling lockable & not lockable (no change) |
| 98 | (!trackLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackLockableFlag. && !trackNotLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNotLockableFlag.)) { // leave lockable as-is in all cases |
| 99 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("%q already supported", pattern)) |
| 100 | continue ArgsLoop |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | lockableArg := "" |
| 106 | if trackLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackLockableFlag. { // no need to test trackNotLockableFlag, if we got here we're disabling |
| 107 | lockableArg = " " + gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.LockableAttribscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/LockableAttrib. |
| 108 | } |
| 109 | |
| 110 | changedAttribLines[pattern] = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s filter=lfs diff=lfs merge=lfs -text%v%s", encodedArg, lockableArg, lineEnd) |
| 111 | |
| 112 | if trackLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackLockableFlag. { |
| 113 | readOnlyPatterns = append(readOnlyPatterns, pattern) |
| 114 | } else { |
| 115 | writeablePatterns = append(writeablePatterns, pattern) |
| 116 | } |
| 117 | |
| 118 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Tracking %q", unescapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/unescapeAttrPattern().(encodedArg))) |
| 119 | } |
| 120 | |
| 121 | // Now read the whole local attributes file and iterate over the contents, |
| 122 | // replacing any lines where the values have changed, and appending new lines |
| 123 | // change this: |
| 124 | |
| 125 | var ( |
| 126 | attribContents []byte |
| 127 | attributesFile *osscip-go gomod github.com/golang/go/src go1.25.0 os/.Filescip-go gomod github.com/golang/go/src go1.25.0 os/File# |
| 128 | ) |
| 129 | if !trackNoModifyAttrsFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoModifyAttrsFlag. { |
| 130 | attribContents, err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(".gitattributes") |
| 131 | // it's fine for file to not exist |
| 132 | if err != nil && !osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 133 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Error reading '.gitattributes' file")) |
| 134 | return |
| 135 | } |
| 136 | // Re-generate the file with merge of old contents and new (to deal with changes) |
| 137 | attributesFile, err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenFilescip-go gomod github.com/golang/go/src go1.25.0 os/OpenFile().(".gitattributes", osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_WRONLYscip-go gomod github.com/golang/go/src go1.25.0 os/O_WRONLY.|osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_TRUNCscip-go gomod github.com/golang/go/src go1.25.0 os/O_TRUNC.|osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_CREATEscip-go gomod github.com/golang/go/src go1.25.0 os/O_CREATE., 0660) |
| 138 | if err != nil { |
| 139 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Error opening '.gitattributes' file")) |
| 140 | return |
| 141 | } |
| 142 | defer attributesFile.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 143 | |
| 144 | if len(attribContents) > 0 { |
| 145 | scanner := bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.25.0 bufio/NewScanner().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(attribContents)) |
| 146 | for scanner.Scanscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Scan().() { |
| 147 | line := scanner.Textscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Text().() |
| 148 | fields := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.25.0 strings/Fields().(line) |
| 149 | if len(fields) < 1 { |
| 150 | continue |
| 151 | } |
| 152 | |
| 153 | pattern := unescapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/unescapeAttrPattern().(fields[0]) |
| 154 | if newline, ok := changedAttribLines[pattern]; ok { |
| 155 | // Replace this line (newline already embedded) |
| 156 | attributesFile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().(newline) |
| 157 | // Remove from map so we know we don't have to add it to the end |
| 158 | delete(changedAttribLines, pattern) |
| 159 | } else { |
| 160 | // Write line unchanged (replace newline) |
| 161 | attributesFile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().(line + lineEnd) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Our method of writing also made sure there's always a newline at end |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | modified := false |
| 170 | sawError := false |
| 171 | // Any items left in the map, write new lines at the end of the file |
| 172 | // Note this is only new patterns, not ones which changed locking flags |
| 173 | for pattern, newline := range changedAttribLines { |
| 174 | // Also, for any new patterns we've added, make sure any existing git |
| 175 | // tracked files have their timestamp updated so they will now show as |
| 176 | // modified note this is relative to current dir which is how we write |
| 177 | // .gitattributes deliberately not done in parallel as a chan because |
| 178 | // we'll be marking modified |
| 179 | // |
| 180 | // NOTE: `git ls-files` does not do well with leading slashes. |
| 181 | // Since all `git-lfs track` calls are relative to the root of |
| 182 | // the repository, the leading slash is simply removed for its |
| 183 | // implicit counterpart. |
| 184 | if trackVerboseLoggingFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackVerboseLoggingFlag. { |
| 185 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Searching for files matching pattern: %s", pattern)) |
| 186 | } |
| 187 | |
| 188 | gittracked, err := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.GetTrackedFilesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/GetTrackedFiles().(pattern) |
| 189 | if err != nil { |
| 190 | Exitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Exit().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Error getting tracked files for %q: %s", pattern, err)) |
| 191 | } |
| 192 | |
| 193 | if trackVerboseLoggingFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackVerboseLoggingFlag. { |
| 194 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Found %d files previously added to Git matching pattern: %s", len(gittracked), pattern)) |
| 195 | } |
| 196 | |
| 197 | var matchedBlocklist bool |
| 198 | for _, f := range gittracked { |
| 199 | if forbidden := blocklistItemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/blocklistItem().(f); forbidden != "" { |
| 200 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Pattern '%s' matches forbidden file '%s'. If you would like to track %s, modify '.gitattributes' manually.", pattern, f, f)) |
| 201 | matchedBlocklist = true |
| 202 | } |
| 203 | } |
| 204 | if matchedBlocklist { |
| 205 | continue |
| 206 | } |
| 207 | |
| 208 | if !trackNoModifyAttrsFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoModifyAttrsFlag. { |
| 209 | // Newline already embedded |
| 210 | attributesFile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().(newline) |
| 211 | } |
| 212 | modified = true |
| 213 | |
| 214 | for _, f := range gittracked { |
| 215 | if trackVerboseLoggingFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackVerboseLoggingFlag. || trackDryRunFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackDryRunFlag. { |
| 216 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Touching %q", f)) |
| 217 | } |
| 218 | |
| 219 | if !trackDryRunFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackDryRunFlag. { |
| 220 | now := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().() |
| 221 | err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Chtimesscip-go gomod github.com/golang/go/src go1.25.0 os/Chtimes().(f, now, now) |
| 222 | if err != nil { |
| 223 | LoggedErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/LoggedError().(err, trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Error marking %q modified: %s", f, err)) |
| 224 | sawError = true |
| 225 | continue |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // now flip read-only mode based on lockable / not lockable changes |
| 232 | lockClient := newLockClientscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/newLockClient().() |
| 233 | err = lockClient.FixFileWriteFlagsInDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/locking`/Client#FixFileWriteFlagsInDir().(relpath, readOnlyPatterns, writeablePatterns) |
| 234 | if err != nil { |
| 235 | LoggedErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/LoggedError().(err, trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Error changing lockable file permissions: %s", err)) |
| 236 | sawError = true |
| 237 | } |
| 238 | |
| 239 | if sawError { |
| 240 | ExitWithCodescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/ExitWithCode().(2) |
| 241 | } |
| 242 | // If we didn't modify things, but that's because the patterns |
| 243 | // were already supported, don't return an error, since what the |
| 244 | // user wanted has already been done. |
| 245 | // Otherwise, if we didn't modify things but only because the |
| 246 | // patterns were disallowed, return an error. |
| 247 | if !modified && len(changedAttribLines) > 0 { |
| 248 | ExitWithCodescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/ExitWithCode().(1) |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | type PatternDatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData# struct { |
| 253 | Patternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Pattern. string `json:"pattern"` |
| 254 | Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Source. string `json:"source"` |
| 255 | Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Lockable. bool `json:"lockable"` |
| 256 | Trackedscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Tracked. bool `json:"tracked"` |
| 257 | } |
| 258 | |
| 259 | func listPatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/listPatterns().() { |
| 260 | knownPatterns, err := getAllKnownPatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/getAllKnownPatterns().() |
| 261 | if err != nil { |
| 262 | Exitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Exit().("unable to list patterns: %s", err) |
| 263 | } |
| 264 | if trackJSONFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackJSONFlag. { |
| 265 | patterns := struct { |
| 266 | Patterns []PatternDatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData# `json:"patterns"` |
| 267 | }{Patterns: make([]PatternDatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#, 0, len(knownPatterns))} |
| 268 | for _, p := range knownPatterns { |
| 269 | patterns.Patterns = append(patterns.Patterns, PatternDatascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#{ |
| 270 | Patternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Pattern.: p.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Path., |
| 271 | Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Source.: p.Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Source..Stringscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributeSource#String().(), |
| 272 | Trackedscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Tracked.: p.Trackedscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Tracked., |
| 273 | Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/PatternData#Lockable.: p.Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Lockable., |
| 274 | }) |
| 275 | } |
| 276 | encoder := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.NewEncoderscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/NewEncoder().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 os/Stdout.) |
| 277 | encoder.SetIndentscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Encoder#SetIndent().("", " ") |
| 278 | err := encoder.Encodescip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Encoder#Encode().(patterns) |
| 279 | if err != nil { |
| 280 | ExitWithErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/ExitWithError().(err) |
| 281 | } |
| 282 | return |
| 283 | } |
| 284 | |
| 285 | if len(knownPatterns) < 1 { |
| 286 | return |
| 287 | } |
| 288 | |
| 289 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Listing tracked patterns")) |
| 290 | for _, t := range knownPatterns { |
| 291 | if t.Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Lockable. { |
| 292 | // TRANSLATORS: Leading spaces here should be preserved. |
| 293 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().(" %s [lockable] (%s)", t.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Path., t.Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Source.)) |
| 294 | } else if t.Trackedscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Tracked. { |
| 295 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(" %s (%s)", t.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Path., t.Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Source.) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if trackNoExcludedFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoExcludedFlag. { |
| 300 | return |
| 301 | } |
| 302 | |
| 303 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Listing excluded patterns")) |
| 304 | for _, t := range knownPatterns { |
| 305 | if !t.Trackedscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Tracked. && !t.Lockablescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Lockable. { |
| 306 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(" %s (%s)", t.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Path., t.Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Source.) |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | func getAllKnownPatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/getAllKnownPatterns().() ([]gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.AttributePathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#, error) { |
| 312 | mp := gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.NewMacroProcessorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/NewMacroProcessor().() |
| 313 | |
| 314 | // Parse these in this order so that macros in one file are properly |
| 315 | // expanded when referred to in a later file, then order them in the |
| 316 | // order we want. |
| 317 | systemPatterns, err := gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.GetSystemAttributePathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/GetSystemAttributePaths().(mp, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Osscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Os.) |
| 318 | if err != nil { |
| 319 | return nil, err |
| 320 | } |
| 321 | userPatterns, err := gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.GetUserAttributePathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/GetUserAttributePaths().(mp, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Git.) |
| 322 | if err != nil { |
| 323 | return nil, err |
| 324 | } |
| 325 | knownPatterns := gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.GetAttributePathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/GetAttributePaths().(mp, cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..LocalWorkingDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#LocalWorkingDir().(), cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..LocalGitDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#LocalGitDir().()) |
| 326 | knownPatterns = append(knownPatterns, userPatterns...) |
| 327 | knownPatterns = append(knownPatterns, systemPatterns...) |
| 328 | |
| 329 | return knownPatterns, nil |
| 330 | } |
| 331 | |
| 332 | func getAttributeLineEndingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/getAttributeLineEnding().(attribs []gitattrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/.AttributePathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#) string { |
| 333 | for _, a := range attribs { |
| 334 | if a.Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Source..Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributeSource#Path. == ".gitattributes" { |
| 335 | return a.Sourcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributePath#Source..LineEndingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/gitattr`/AttributeSource#LineEnding. |
| 336 | } |
| 337 | } |
| 338 | return "" |
| 339 | } |
| 340 | |
| 341 | // blocklistItem returns the name of the blocklist item preventing the given |
| 342 | // file-name from being tracked, or an empty string, if there is none. |
| 343 | func blocklistItemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/blocklistItem().(name string) string { |
| 344 | base := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Base().(name) |
| 345 | |
| 346 | for _, p := range prefixBlocklistscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prefixBlocklist. { |
| 347 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(base, p) { |
| 348 | return p |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return "" |
| 353 | } |
| 354 | |
| 355 | var ( |
| 356 | trackEscapePatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackEscapePatterns. = map[string]string{ |
| 357 | " ": "[[:space:]]", |
| 358 | "#": "\\#", |
| 359 | } |
| 360 | trackEscapeStringsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackEscapeStrings. = []string{"*", "[", "]", "?"} |
| 361 | ) |
| 362 | |
| 363 | func escapeGlobCharactersscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/escapeGlobCharacters().(s string) string { |
| 364 | var escaped string |
| 365 | if runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS. == "windows" { |
| 366 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(s, `\`, "/", -1) |
| 367 | } else { |
| 368 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(s, `\`, `\\`, -1) |
| 369 | } |
| 370 | |
| 371 | for _, ch := range trackEscapeStringsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackEscapeStrings. { |
| 372 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(escaped, ch, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("\\%s", ch), -1) |
| 373 | } |
| 374 | |
| 375 | for from, to := range trackEscapePatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackEscapePatterns. { |
| 376 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(escaped, from, to, -1) |
| 377 | } |
| 378 | return escaped |
| 379 | } |
| 380 | |
| 381 | func escapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/escapeAttrPattern().(s string) string { |
| 382 | var escaped string |
| 383 | if runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS. == "windows" { |
| 384 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(s, `\`, "/", -1) |
| 385 | } else { |
| 386 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(s, `\`, `\\`, -1) |
| 387 | } |
| 388 | |
| 389 | for from, to := range trackEscapePatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackEscapePatterns. { |
| 390 | escaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(escaped, from, to, -1) |
| 391 | } |
| 392 | |
| 393 | return escaped |
| 394 | } |
| 395 | |
| 396 | func unescapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/unescapeAttrPattern().(escaped string) string { |
| 397 | var unescaped string = escaped |
| 398 | |
| 399 | for to, from := range trackEscapePatternsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackEscapePatterns. { |
| 400 | unescaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(unescaped, from, to, -1) |
| 401 | } |
| 402 | |
| 403 | if runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS. != "windows" { |
| 404 | unescaped = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(unescaped, `\\`, `\`, -1) |
| 405 | } |
| 406 | |
| 407 | return unescaped |
| 408 | } |
| 409 | |
| 410 | func initscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/init().() { |
| 411 | RegisterCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/RegisterCommand().("track", trackCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackCommand()., func(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#) { |
| 412 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackLockableFlag., "lockable", "l", false, "make pattern lockable, i.e. read-only unless locked") |
| 413 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackNotLockableFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNotLockableFlag., "not-lockable", "", false, "remove lockable attribute from pattern") |
| 414 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackVerboseLoggingFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackVerboseLoggingFlag., "verbose", "v", false, "log which files are being tracked and modified") |
| 415 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackDryRunFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackDryRunFlag., "dry-run", "d", false, "preview results of running `git lfs track`") |
| 416 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackNoModifyAttrsFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoModifyAttrsFlag., "no-modify-attrs", "", false, "skip modifying .gitattributes file") |
| 417 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackNoExcludedFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackNoExcludedFlag., "no-excluded", "", false, "skip listing excluded paths") |
| 418 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackFilenameFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackFilenameFlag., "filename", "", false, "treat this pattern as a literal filename") |
| 419 | cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&trackJSONFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/trackJSONFlag., "json", "j", false, "print output in JSON") |
| 420 | }) |
| 421 | } |