Skip to content

Commit

Permalink
backend: Support file deletion in GitHub CreateBranch (#3104)
Browse files Browse the repository at this point in the history
  • Loading branch information
septum authored Aug 29, 2024
1 parent 8c59b7b commit 9998f12
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions backend/service/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,21 @@ func (s *svc) CreateBranch(ctx context.Context, req *CreateBranchRequest) error
}

for filename, contents := range req.Files {
fh, err := wt.Filesystem.Create(filename)
if err != nil {
return err
}
if _, err := io.Copy(fh, contents); err != nil {
return err
}
if err := wt.AddWithOptions(&git.AddOptions{Path: filename}); err != nil {
return err
if contents == nil {
if err := wt.Filesystem.Remove(filename); err != nil {
return err
}
} else {
fh, err := wt.Filesystem.Create(filename)
if err != nil {
return err
}
if _, err := io.Copy(fh, contents); err != nil {
return err
}
if err := wt.AddWithOptions(&git.AddOptions{Path: filename}); err != nil {
return err
}
}
}

Expand Down

0 comments on commit 9998f12

Please sign in to comment.