|
7 | 7 | "os/exec"
|
8 | 8 | "sort"
|
9 | 9 | "strconv"
|
| 10 | + "strings" |
10 | 11 | "sync"
|
11 | 12 |
|
12 | 13 | timeago "github.com/caarlos0/timea.go"
|
@@ -133,31 +134,33 @@ func main() {
|
133 | 134 | os.Exit(1)
|
134 | 135 | }
|
135 | 136 |
|
136 |
| - desiredBranch := branches[desiredBranchNumber] |
| 137 | + // When option -a/--all is used to display remote branches, |
| 138 | + // we want to remove origin/ prefix to have local branches on the computer |
| 139 | + desiredBranchName := strings.Replace(branches[desiredBranchNumber].name, "origin/", "", 1) |
137 | 140 |
|
138 | 141 | if deleteMode {
|
139 | 142 | // Temporary reclacement of the native command
|
140 |
| - cmd := exec.Command("git", "branch", "-D", desiredBranch.name) |
| 143 | + cmd := exec.Command("git", "branch", "-D", desiredBranchName) |
141 | 144 | cmd.Output()
|
142 | 145 |
|
143 | 146 | ClearTerminal()
|
144 | 147 |
|
145 | 148 | cyan := color.New(color.Bold, color.FgCyan).SprintFunc()
|
146 | 149 | bgYellow := color.New(color.Bold, color.BgYellow).SprintFunc()
|
147 |
| - fmt.Println(bgYellow(cyan("branch ", desiredBranch.name, " deleted!"))) |
| 150 | + fmt.Println(bgYellow(cyan("branch ", desiredBranchName, " deleted!"))) |
148 | 151 | } else {
|
149 | 152 | // worktree, _ := r.Worktree()
|
150 | 153 | // error := worktree.Checkout(&git.CheckoutOptions{
|
151 | 154 | // Branch: plumbing.NewBranchReferenceName(desiredBranch.name),
|
152 | 155 | // })
|
153 | 156 |
|
154 | 157 | // Temporary reclacement of the native command
|
155 |
| - cmd := exec.Command("git", "checkout", desiredBranch.name) |
| 158 | + cmd := exec.Command("git", "checkout", desiredBranchName) |
156 | 159 | cmd.Output()
|
157 | 160 |
|
158 | 161 | ClearTerminal()
|
159 | 162 |
|
160 | 163 | purple := color.New(color.Bold, color.FgHiMagenta).SprintFunc()
|
161 |
| - fmt.Println(purple("Checkout the branch ", desiredBranch.name, "!")) |
| 164 | + fmt.Println(purple("Checkout the branch ", desiredBranchName, "!")) |
162 | 165 | }
|
163 | 166 | }
|
0 commit comments