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

Method acceptAllHunksInFile

internal/ui/app.go:282–341  ·  view source on GitHub ↗
(path string, mode git.PatchMode, revision string)

Source from the content-addressed store, hash-verified

280}
281
282func (a *App) acceptAllHunksInFile(path string, mode git.PatchMode, revision string) error {
283 hunks, err := a.repo.ParseDiff(path, mode, revision)
284 if err != nil {
285 return err
286 }
287
288 if len(hunks) == 0 {
289 return nil
290 }
291
292 actualHunks := hunks[1:]
293 if len(actualHunks) == 0 {
294 return nil
295 }
296
297 // Apply auto-splitting FIRST if enabled (before filtering)
298 if a.autoSplitEnabled {
299 originalCount := len(actualHunks)
300 actualHunks = a.autoSplitAllHunks(actualHunks)
301 if len(actualHunks) > originalCount {
302 fmt.Printf("Auto-split enabled: expanded %d hunks into %d smaller hunks in %s\n", originalCount, len(actualHunks), path)
303 }
304 }
305
306 // Apply global filter AFTER auto-splitting
307 if a.globalFilter != "" {
308 filteredHunks := a.filterHunksByRegex(actualHunks, a.globalFilter)
309 if len(filteredHunks) == 0 {
310 fmt.Printf("No hunks in %s match global filter: %s\n", path, a.globalFilter)
311 return nil
312 }
313 fmt.Printf("Applied global filter '%s' to %s: accepting %d of %d hunks\n", a.globalFilter, path, len(filteredHunks), len(actualHunks))
314 actualHunks = filteredHunks
315 }
316
317 // Accept all hunks
318 for i := 0; i < len(actualHunks); i++ {
319 use := true
320 actualHunks[i].Use = &use
321 }
322
323 // Apply the patch
324 selectedHunks := []git.Hunk{hunks[0]}
325 for _, hunk := range actualHunks {
326 if hunk.Use != nil && *hunk.Use {
327 selectedHunks = append(selectedHunks, hunk)
328 }
329 }
330
331 if len(selectedHunks) > 1 {
332 patchData := a.reassemblePatch(selectedHunks)
333 if err := a.repo.ApplyPatch(patchData, mode); err != nil {
334 return fmt.Errorf("failed to apply patch for %s: %v", path, err)
335 }
336 a.repo.UpdateIndex()
337 fmt.Printf("Accepted all hunks in %s\n", path)
338 }
339

Callers 1

RunPatchModeMethod · 0.95

Calls 6

autoSplitAllHunksMethod · 0.95
filterHunksByRegexMethod · 0.95
reassemblePatchMethod · 0.95
ParseDiffMethod · 0.80
ApplyPatchMethod · 0.80
UpdateIndexMethod · 0.80

Tested by

no test coverage detected