CreateFile is a convenience method to set the contents of a file in the repo and stage it.
(filename string, data []byte)
| 42 | // CreateFile is a convenience method to set the contents of a file in the |
| 43 | // repo and stage it. |
| 44 | func (r *Repository) CreateFile(filename string, data []byte) error { |
| 45 | f, err := r.WorktreeFS.Create(filename) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | _, err = f.Write(data) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | _, err = r.Worktree.Add(filename) |
| 56 | |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | // UpdateFile is a convenience method to get the contents of a file, pass it |
| 61 | // to a callback, write the contents back to the file if no error was |