~porcellis/t

ref: structure t/commands/commit.go -rw-r--r-- 720 bytes
76f0d055 — Pedro Lucas Porcellis Generate a simple and nice doc 1 year, 9 months ago
                                                                                
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
package commands

import (
	"fmt"
	"git.sr.ht/~porcellis/t/config"
	"git.sr.ht/~porcellis/t/models"
	"os"
	"os/exec"
)

func AddToStagedList(basePath string, notePath string) error {
	cmd := exec.Command("git", "-C", basePath, "add", notePath)
	cmd.Stdin = nil
	cmd.Stdout = nil
	cmd.Stderr = os.Stderr

	return cmd.Run()
}

func Commit(config config.TConfig, note models.Note) error {
	var (
		err error
	)

	err = AddToStagedList(config.BasePath, note.Path)

	if err != nil {
		return err
	}

	commitMessage := fmt.Sprintf("Modified '%s'", note.Title())

	cmd := exec.Command("git", "-C", config.BasePath, "commit", "-am", commitMessage)
	cmd.Stdin = nil
	cmd.Stdout = nil
	cmd.Stderr = os.Stderr

	return cmd.Run()
}