MCPcopy
hub / github.com/git-lfs/git-lfs / trackCommand

Function trackCommand

commands/command_track.go:37–250  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

35)
36
37func trackCommand(cmd *cobra.Command, args []string) {
38 requireGitVersion()
39 setupWorkingCopy()
40
41 if trackDryRunFlag {
42 trackNoModifyAttrsFlag = true
43 }
44
45 if !cfg.Os.Bool("GIT_LFS_TRACK_NO_INSTALL_HOOKS", false) {
46 installHooks(false)
47 }
48
49 if len(args) == 0 {
50 listPatterns()
51 return
52 }
53
54 if trackJSONFlag {
55 Exit(tr.Tr.Get("--json option can't be combined with arguments"))
56 }
57
58 mp := gitattr.NewMacroProcessor()
59
60 // Intentionally do _not_ consider global- and system-level
61 // .gitattributes here. Parse them still to expand any macros.
62 git.GetSystemAttributePaths(mp, cfg.Os)
63 git.GetRootAttributePaths(mp, cfg.Git)
64 knownPatterns := git.GetAttributePaths(mp, cfg.LocalWorkingDir(), cfg.LocalGitDir())
65 lineEnd := getAttributeLineEnding(knownPatterns)
66 if len(lineEnd) == 0 {
67 lineEnd = gitLineEnding(cfg.Git)
68 }
69
70 wd, _ := tools.Getwd()
71 wd = tools.ResolveSymlinks(wd)
72 relpath, err := filepath.Rel(cfg.LocalWorkingDir(), wd)
73 if err != nil {
74 Exit(tr.Tr.Get("Current directory %q outside of Git working directory %q.", wd, cfg.LocalWorkingDir()))
75 }
76
77 changedAttribLines := make(map[string]string)
78 var readOnlyPatterns []string
79 var writeablePatterns []string
80ArgsLoop:
81 for _, unsanitizedPattern := range args {
82 pattern := tools.TrimCurrentPrefix(cleanRootPath(unsanitizedPattern))
83
84 // Generate the new / changed attrib line for merging
85 var encodedArg string
86 if trackFilenameFlag {
87 encodedArg = escapeGlobCharacters(pattern)
88 pattern = escapeGlobCharacters(pattern)
89 } else {
90 encodedArg = escapeAttrPattern(pattern)
91 }
92
93 if !trackNoModifyAttrsFlag {
94 for _, known := range knownPatterns {

Callers

nothing calls this directly

Calls 15

NewMacroProcessorFunction · 0.92
GetSystemAttributePathsFunction · 0.92
GetRootAttributePathsFunction · 0.92
GetAttributePathsFunction · 0.92
GetwdFunction · 0.92
ResolveSymlinksFunction · 0.92
TrimCurrentPrefixFunction · 0.92
GetTrackedFilesFunction · 0.92
requireGitVersionFunction · 0.85
setupWorkingCopyFunction · 0.85
installHooksFunction · 0.85
listPatternsFunction · 0.85

Tested by

no test coverage detected