UpdateFile is a convenience method to get the contents of a file, pass it to a callback, write the contents back to the file if no error was returned, and stage the file.
(filename string, cb func([]byte) ([]byte, error))
| 61 | // to a callback, write the contents back to the file if no error was |
| 62 | // returned, and stage the file. |
| 63 | func (r *Repository) UpdateFile(filename string, cb func([]byte) ([]byte, error)) error { |
| 64 | data, _ := r.GetFile(filename) |
| 65 | |
| 66 | data, err := cb(data) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | return r.CreateFile(filename, data) |
| 72 | } |
| 73 | |
| 74 | // Commit is a convenience method to make working with the worktree a little |
| 75 | // bit easier. |
no test coverage detected