-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommitter.go
72 lines (62 loc) · 1.38 KB
/
committer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"bytes"
"fmt"
"io"
"log"
"os"
"time"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)
func (c *Cru) Commit() (hash plumbing.Hash, err error) {
if c.CommitMsg == "" {
return plumbing.ZeroHash, fmt.Errorf("a commit message is required")
}
for _, path := range c.updatedFiles {
_, err = c.workTree.Add(c.RelPath(path))
if err != nil {
return plumbing.ZeroHash, err
}
if c.Verbose {
log.Printf("INFO: %s added to commit\n", c.RelPath(path))
}
}
if !c.DryRun {
hash, err = c.workTree.Commit(c.CommitMsg, &git.CommitOptions{
Author: &object.Signature{
Name: c.Username,
Email: c.Email,
When: time.Now(),
},
})
if err != nil {
log.Printf("ERROR: failed to commit changes, %s\n", err)
c.workTree.Reset(nil)
}
if c.Verbose {
log.Printf("INFO: changes committed with %s", hash.String()[0:7])
}
} else {
hash = plumbing.ZeroHash
}
return
}
func (c *Cru) Push() error {
if !c.DryRun {
var progress io.Writer = os.Stderr
if !c.Verbose {
progress = &bytes.Buffer{}
}
log.Printf("INFO: pushing changes to %s", c.Url)
auth, _, err := GetAuth(c.Url)
if err != nil {
return err
}
return c.repository.Push(&git.PushOptions{Auth: auth, Progress: progress})
} else {
log.Printf("INFO: changes would be pushed to %s", c.Url)
}
return nil
}