(ctx context.Context, f *gitdiff.File)
| 157 | } |
| 158 | |
| 159 | func (a *GraphQLApplier) applyModify(ctx context.Context, f *gitdiff.File) error { |
| 160 | data, exists, err := a.getContent(ctx, f.OldName) |
| 161 | if err != nil { |
| 162 | return err |
| 163 | } |
| 164 | if !exists { |
| 165 | return &Conflict{Type: ConflictModifiedFileMissing, File: f.OldName} |
| 166 | } |
| 167 | |
| 168 | if len(f.TextFragments) > 0 || f.BinaryFragment != nil { |
| 169 | var b bytes.Buffer |
| 170 | if err := apply(&b, bytes.NewReader(data), f.OldName, f); err != nil { |
| 171 | return err |
| 172 | } |
| 173 | data = b.Bytes() |
| 174 | } |
| 175 | |
| 176 | // delete the old file if it was removed |
| 177 | if f.OldName != f.NewName { |
| 178 | a.changes[f.OldName] = pendingChange{IsDelete: true} |
| 179 | } |
| 180 | |
| 181 | a.changes[f.NewName] = pendingChange{Content: data} |
| 182 | a.modeCache[f.NewName] = defaultMode |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | func (a *GraphQLApplier) getContent(ctx context.Context, filePath string) ([]byte, bool, error) { |
| 187 | if existing, ok := a.changes[filePath]; ok { |
no test coverage detected