Skip to content

Commit 62415cf

Browse files
authored
feat: when selecting remote branch, use local branch for the local (#10)
1 parent 157df1c commit 62415cf

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"sort"
99
"strconv"
10+
"strings"
1011
"sync"
1112

1213
timeago "github.com/caarlos0/timea.go"
@@ -133,31 +134,33 @@ func main() {
133134
os.Exit(1)
134135
}
135136

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)
137140

138141
if deleteMode {
139142
// Temporary reclacement of the native command
140-
cmd := exec.Command("git", "branch", "-D", desiredBranch.name)
143+
cmd := exec.Command("git", "branch", "-D", desiredBranchName)
141144
cmd.Output()
142145

143146
ClearTerminal()
144147

145148
cyan := color.New(color.Bold, color.FgCyan).SprintFunc()
146149
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!")))
148151
} else {
149152
// worktree, _ := r.Worktree()
150153
// error := worktree.Checkout(&git.CheckoutOptions{
151154
// Branch: plumbing.NewBranchReferenceName(desiredBranch.name),
152155
// })
153156

154157
// Temporary reclacement of the native command
155-
cmd := exec.Command("git", "checkout", desiredBranch.name)
158+
cmd := exec.Command("git", "checkout", desiredBranchName)
156159
cmd.Output()
157160

158161
ClearTerminal()
159162

160163
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, "!"))
162165
}
163166
}

version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/fatih/color"
88
)
99

10-
const Version string = "0.1.0"
11-
const BuildDate string = "2024-07-25"
10+
const Version string = "0.2.0"
11+
const BuildDate string = "2024-08-08"
1212

1313
func cliCommandDisplayHelp(args []string) {
1414
displayVersion := StringInSlice("-v", args[1:]) || StringInSlice("--version", args[1:])

0 commit comments

Comments
 (0)