|
|
|
@ -205,6 +205,7 @@ type Message struct { |
|
|
|
|
Scope string |
|
|
|
|
Subject string |
|
|
|
|
Files []string |
|
|
|
|
News []string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Message) String() string { |
|
|
|
@ -247,13 +248,6 @@ func (m *Message) Valid() bool { |
|
|
|
|
return len(m.Type) > 0 && len(m.Subject) > 0 && len(m.Files) > 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type file struct { |
|
|
|
|
Name string |
|
|
|
|
Add bool |
|
|
|
|
Del bool |
|
|
|
|
New bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func readFiles(path string, f func(string)) error { |
|
|
|
|
entries, err := os.ReadDir(path) |
|
|
|
|
if err != nil { |
|
|
|
@ -312,6 +306,7 @@ func (m *Message) AskFiles() error { |
|
|
|
|
} |
|
|
|
|
opts = append(opts, s) |
|
|
|
|
infos[s] = "新增" |
|
|
|
|
m.News = append(m.News, s) |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
@ -336,6 +331,7 @@ func (m *Message) AskFiles() error { |
|
|
|
|
infos[name] = "更新但未合并" |
|
|
|
|
case '?': |
|
|
|
|
infos[name] = "新增" |
|
|
|
|
m.News = append(m.News, name) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -504,7 +500,21 @@ func (m *Message) Confirm() (bool, error) { |
|
|
|
|
return true, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Message) AddNews() error { |
|
|
|
|
args := append([]string{"add"}, m.News...) |
|
|
|
|
cmd := exec.Command("git", args...) |
|
|
|
|
cmd.Stdout = os.Stdout |
|
|
|
|
cmd.Stderr = os.Stderr |
|
|
|
|
return cmd.Run() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Message) Commit() error { |
|
|
|
|
if len(m.News) > 0 { |
|
|
|
|
err := m.AddNews() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
args := []string{"commit", "-o"} |
|
|
|
|
for _, f := range m.Files { |
|
|
|
|
args = append(args, "./"+f) |
|
|
|
@ -517,10 +527,6 @@ func (m *Message) Commit() error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
//readFiles(".", func(s string) {
|
|
|
|
|
// fmt.Println(s)
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
|
|
var msg Message |
|
|
|
|
ok, err := msg.Confirm() |
|
|
|
|
if err == nil && ok { |
|
|
|
|