MCPcopy Create free account
hub / github.com/cwarden/git-add--interactive / patchUpdateFile

Method patchUpdateFile

internal/ui/patch.go:125–492  ·  view source on GitHub ↗
(path string, mode git.PatchMode, revision string)

Source from the content-addressed store, hash-verified

123}
124
125func (a *App) patchUpdateFile(path string, mode git.PatchMode, revision string) error {
126 hunks, err := a.repo.ParseDiff(path, mode, revision)
127 if err != nil {
128 return err
129 }
130
131 if len(hunks) == 0 {
132 return nil
133 }
134
135 for _, line := range hunks[0].Display {
136 fmt.Println(line)
137 }
138
139 actualHunks := hunks[1:]
140 if len(actualHunks) == 0 {
141 return nil
142 }
143
144 // Apply auto-splitting FIRST if enabled (before filtering)
145 if a.autoSplitEnabled {
146 originalCount := len(actualHunks)
147 actualHunks = a.autoSplitAllHunks(actualHunks)
148 if len(actualHunks) > originalCount {
149 fmt.Printf("Auto-split enabled: expanded %d hunks into %d smaller hunks\n", originalCount, len(actualHunks))
150 } else {
151 fmt.Printf("Auto-split enabled: %d hunks (no further splitting possible)\n", len(actualHunks))
152 }
153 }
154
155 // Apply global filter AFTER auto-splitting
156 if a.globalFilter != "" {
157 filteredHunks := a.filterHunksByRegex(actualHunks, a.globalFilter)
158 if len(filteredHunks) == 0 {
159 fmt.Printf("No hunks in this file match global filter: %s\n", a.globalFilter)
160 return nil
161 }
162 fmt.Printf("Applied global filter '%s': showing %d of %d hunks\n", a.globalFilter, len(filteredHunks), len(actualHunks))
163 actualHunks = filteredHunks
164 }
165
166 ix := 0
167 for {
168 if ix >= len(actualHunks) {
169 break
170 }
171
172 hunk := &actualHunks[ix]
173 if hunk.Use != nil {
174 ix++
175 continue
176 }
177
178 other := a.buildOtherOptions(actualHunks, ix)
179
180 for _, line := range hunk.Display {
181 fmt.Println(line)
182 }

Callers 1

RunPatchModeMethod · 0.95

Calls 14

autoSplitAllHunksMethod · 0.95
filterHunksByRegexMethod · 0.95
buildOtherOptionsMethod · 0.95
coloredMethod · 0.95
promptSingleCharMethod · 0.95
reassemblePatchMethod · 0.95
printErrorMethod · 0.95
editHunkMethod · 0.95
hunkMatchesRegexMethod · 0.95
ParseDiffMethod · 0.80
ApplyPatchMethod · 0.80
UpdateIndexMethod · 0.80

Tested by

no test coverage detected