(cmd *Command, args *Args)
| 39 | } |
| 40 | |
| 41 | func sync(cmd *Command, args *Args) { |
| 42 | localRepo, err := github.LocalRepo() |
| 43 | utils.Check(err) |
| 44 | |
| 45 | remote, err := localRepo.MainRemote() |
| 46 | utils.Check(err) |
| 47 | |
| 48 | defaultBranch := localRepo.DefaultBranch(remote).ShortName() |
| 49 | fullDefaultBranch := fmt.Sprintf("refs/remotes/%s/%s", remote.Name, defaultBranch) |
| 50 | currentBranch := "" |
| 51 | if curBranch, err := localRepo.CurrentBranch(); err == nil { |
| 52 | currentBranch = curBranch.ShortName() |
| 53 | } |
| 54 | |
| 55 | err = git.Spawn("fetch", "--prune", "--quiet", "--progress", remote.Name) |
| 56 | utils.Check(err) |
| 57 | |
| 58 | branchToRemote := map[string]string{} |
| 59 | if lines, err := git.ConfigAll("branch.*.remote"); err == nil { |
| 60 | configRe := regexp.MustCompile(`^branch\.(.+?)\.remote (.+)`) |
| 61 | |
| 62 | for _, line := range lines { |
| 63 | if matches := configRe.FindStringSubmatch(line); len(matches) > 0 { |
| 64 | branchToRemote[matches[1]] = matches[2] |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | branches, err := git.LocalBranches() |
| 70 | utils.Check(err) |
| 71 | |
| 72 | var green, |
| 73 | lightGreen, |
| 74 | red, |
| 75 | lightRed, |
| 76 | resetColor string |
| 77 | |
| 78 | colorize := colorizeOutput(args.Flag.HasReceived("--color"), args.Flag.Value("--color")) |
| 79 | if colorize { |
| 80 | green = "\033[32m" |
| 81 | lightGreen = "\033[32;1m" |
| 82 | red = "\033[31m" |
| 83 | lightRed = "\033[31;1m" |
| 84 | resetColor = "\033[0m" |
| 85 | } |
| 86 | |
| 87 | for _, branch := range branches { |
| 88 | fullBranch := fmt.Sprintf("refs/heads/%s", branch) |
| 89 | remoteBranch := fmt.Sprintf("refs/remotes/%s/%s", remote.Name, branch) |
| 90 | gone := false |
| 91 | |
| 92 | if branchToRemote[branch] == remote.Name { |
| 93 | if upstream, err := git.SymbolicFullName(fmt.Sprintf("%s@{upstream}", branch)); err == nil { |
| 94 | remoteBranch = upstream |
| 95 | } else { |
| 96 | remoteBranch = "" |
| 97 | gone = true |
| 98 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…