Add compact command

This commit is contained in:
Trevor Slocum 2019-04-08 23:58:27 -07:00
parent 5915a8bc2a
commit b0e56877a6
2 changed files with 25 additions and 0 deletions

15
main.go
View File

@ -70,6 +70,21 @@ func main() {
return nil
},
},
{
Name: "compact",
Aliases: []string{"c"},
Usage: "compact all notebook",
Action: func(c *cli.Context) error {
Initialize(configPath, debug)
for _, notebook := range stick.Notebooks {
notebook.Compact()
}
fmt.Println("notebooks compacted")
return nil
},
},
{
Name: "resolve",
Aliases: []string{"r"},

View File

@ -1,6 +1,7 @@
package main
import (
"os/exec"
"strings"
"github.com/pkg/errors"
@ -176,3 +177,12 @@ func (n *Notebook) File(id string) *object.File {
return file
}
func (n *Notebook) Compact() {
tree, err := n.Repository.Worktree()
CheckError(err)
cmd := exec.Command("git", "-C", tree.Filesystem.Root(), "gc", "--aggressive", "--prune=now")
err = cmd.Run()
CheckError(err)
}