(path string, mode git.PatchMode, revision string)
| 123 | } |
| 124 | |
| 125 | func (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 | } |
no test coverage detected