pull.go

 1package commands
 2
 3import (
 4	"errors"
 5	"fmt"
 6	"github.com/MichaelMure/git-bug/bug"
 7	"github.com/spf13/cobra"
 8)
 9
10func runPull(cmd *cobra.Command, args []string) error {
11	if len(args) > 1 {
12		return errors.New("Only pulling from one remote at a time is supported")
13	}
14
15	remote := "origin"
16	if len(args) == 1 {
17		remote = args[0]
18	}
19
20	fmt.Printf("Fetching remote ...\n\n")
21
22	if err := bug.Fetch(repo, remote); err != nil {
23		return err
24	}
25
26	fmt.Printf("\nMerging data ...\n\n")
27
28	for merge := range bug.MergeAll(repo, remote) {
29		if merge.Err != nil {
30			return merge.Err
31		}
32
33		if merge.Status != bug.MsgNothing {
34			fmt.Printf("%s: %s\n", merge.HumanId, merge.Status)
35		}
36	}
37
38	return nil
39}
40
41// showCmd defines the "push" subcommand.
42var pullCmd = &cobra.Command{
43	Use:   "pull [<remote>]",
44	Short: "Pull bugs update from a git remote",
45	RunE:  runPull,
46}
47
48func init() {
49	RootCmd.AddCommand(pullCmd)
50}