Skip to content

Commit 35a0314

Browse files
committed
feat(branch): Add UI support for creating new branch
Add UI support for creating new branch Signed-off-by: mritd <[email protected]>
1 parent 1c29b1e commit 35a0314

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

apps.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ func newBranchApp(ct string) *cli.App {
5252
if c.NArg() != 1 {
5353
return cli.ShowAppHelp(c)
5454
}
55-
err := createBranch(fmt.Sprintf("%s/%s", ct, c.Args().First()))
56-
if err != nil {
57-
return fmt.Errorf("failed to create branch %s/%s: %s", ct, c.Args().First(), err)
58-
}
59-
return nil
55+
56+
m := newResultModel()
57+
m.message, m.err = createBranch(fmt.Sprintf("%s/%s", ct, c.Args().First()))
58+
59+
return tea.NewProgram(&m).Start()
6060
},
6161
}
6262
}

git_wapper.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ import (
1313
"strings"
1414
)
1515

16-
func createBranch(name string) error {
16+
func createBranch(name string) (string, error) {
1717
err := repoCheck()
1818
if err != nil {
19-
return fmt.Errorf("the current directory is not a git repository")
19+
return "", err
2020
}
21-
return gitCommand(os.Stdout, "checkout", "-b", name)
21+
var buf bytes.Buffer
22+
err = gitCommand(&buf, "checkout", "-b", name)
23+
if err != nil {
24+
return "", errors.New(strings.TrimSpace(buf.String()))
25+
}
26+
27+
return strings.TrimSpace(buf.String()), nil
2228
}
2329

2430
func hasStagedFiles() error {

0 commit comments

Comments
 (0)