1package commands
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/bug"
8 "github.com/MichaelMure/git-bug/cache"
9 "github.com/MichaelMure/git-bug/entity"
10 "github.com/MichaelMure/git-bug/util/interrupt"
11 "github.com/spf13/cobra"
12)
13
14func runPull(cmd *cobra.Command, args []string) error {
15 if len(args) > 1 {
16 return errors.New("Only pulling from one remote at a time is supported")
17 }
18
19 remote := "origin"
20 if len(args) == 1 {
21 remote = args[0]
22 }
23
24 backend, err := cache.NewRepoCache(repo)
25 if err != nil {
26 return err
27 }
28 defer backend.Close()
29 interrupt.RegisterCleaner(backend.Close)
30
31 fmt.Println("Fetching remote ...")
32
33 stdout, err := backend.Fetch(remote)
34 if err != nil {
35 return err
36 }
37
38 fmt.Println(stdout)
39
40 fmt.Println("Merging data ...")
41
42 for result := range backend.MergeAll(remote) {
43 if result.Err != nil {
44 fmt.Println(result.Err)
45 }
46
47 if result.Status != entity.MergeStatusNothing {
48 fmt.Printf("%s: %s\n", bug.FormatHumanID(result.Id), result)
49 }
50 }
51
52 return nil
53}
54
55// showCmd defines the "push" subcommand.
56var pullCmd = &cobra.Command{
57 Use: "pull [<remote>]",
58 Short: "Pull bugs update from a git remote.",
59 PreRunE: loadRepo,
60 RunE: runPull,
61}
62
63func init() {
64 RootCmd.AddCommand(pullCmd)
65}