Skip to content

Commit

Permalink
gogit: Auto-stage files from WithFiles
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
  • Loading branch information
Paulo Gomes committed Dec 6, 2022
1 parent 49c90f6 commit 49c2b22
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions git/gogit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,27 @@ func (g *Client) Commit(info git.Commit, commitOpts ...repository.CommitOption)
o(options)
}

wt, err := g.repository.Worktree()
if err != nil {
return "", err
}

var changed bool
for path, content := range options.Files {
if err := g.writeFile(path, content); err != nil {
return "", err
}
}

wt, err := g.repository.Worktree()
if err != nil {
return "", err
if _, err = wt.Add(path); err != nil {
return "", fmt.Errorf("cannot stage file from options.Files: %w", err)
}
changed = true
}

status, err := wt.Status()
if err != nil {
return "", err
}

var changed bool
for file := range status {
_, _ = wt.Add(file)
changed = true
Expand Down

0 comments on commit 49c2b22

Please sign in to comment.