Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test4 #443

Closed
wants to merge 1 commit into from
Closed

test4 #443

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions ui/components/reposection/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,49 @@ func (m *Model) fastForward() (tea.Cmd, error) {
}), nil
}

func (m *Model) push() (tea.Cmd, error) {
type pushOptions struct {
force bool
}

func (m *Model) push(opts pushOptions) (tea.Cmd, error) {
b := m.getCurrBranch()

taskId := fmt.Sprintf("push_%s_%d", b.Data.Name, time.Now().Unix())
withForceText := func() string {
if opts.force {
return " with force"
}
return ""
}
task := context.Task{
Id: taskId,
StartText: fmt.Sprintf("Pushing branch %s", b.Data.Name),
FinishedText: fmt.Sprintf("Branch %s has been pushed", b.Data.Name),
StartText: fmt.Sprintf("Pushing branch %s%s", b.Data.Name, withForceText()),
FinishedText: fmt.Sprintf("Branch %s has been pushed%s", b.Data.Name, withForceText()),
State: context.TaskStart,
Error: nil,
}
startCmd := m.Ctx.StartTask(task)
return tea.Batch(startCmd, func() tea.Msg {
var err error
args := []string{}
if opts.force {
args = append(args, "--force")
}
if len(b.Data.Remotes) == 0 {
err = gitm.Push(*m.Ctx.RepoPath, "origin", b.Data.Name, gitm.PushOptions{CommandOptions: gitm.CommandOptions{Args: []string{"--set-upstream"}}})
args = append(args, "--set-upstream")
err = gitm.Push(
*m.Ctx.RepoPath,
"origin",
b.Data.Name,
gitm.PushOptions{CommandOptions: gitm.CommandOptions{Args: args}},
)
} else {
err = gitm.Push(*m.Ctx.RepoPath, b.Data.Remotes[0], b.Data.Name)
err = gitm.Push(
*m.Ctx.RepoPath,
b.Data.Remotes[0],
b.Data.Name,
gitm.PushOptions{CommandOptions: gitm.CommandOptions{Args: args}},
)
}
if err != nil {
return constants.TaskFinishedMsg{TaskId: taskId, Err: err}
Expand Down
7 changes: 6 additions & 1 deletion ui/components/reposection/reposection.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ func (m *Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {
}

case key.Matches(msg, keys.BranchKeys.Push):
cmd, err = m.push()
cmd, err = m.push(pushOptions{force: false})
if err != nil {
m.Ctx.Error = err
}
case key.Matches(msg, keys.BranchKeys.ForcePush):
cmd, err = m.push(pushOptions{force: true})
if err != nil {
m.Ctx.Error = err
}
Expand Down
8 changes: 8 additions & 0 deletions ui/keys/branchKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type BranchKeyMap struct {
New key.Binding
FastForward key.Binding
Push key.Binding
ForcePush key.Binding
Delete key.Binding
ViewPRs key.Binding
}
Expand All @@ -35,6 +36,10 @@ var BranchKeys = BranchKeyMap{
key.WithKeys("P"),
key.WithHelp("P", "push"),
),
ForcePush: key.NewBinding(
key.WithKeys("F"),
key.WithHelp("F", "force-push"),
),
Delete: key.NewBinding(
key.WithKeys("d", "backspace"),
key.WithHelp("d/backspace", "delete"),
Expand All @@ -50,6 +55,7 @@ func BranchFullHelp() []key.Binding {
BranchKeys.Checkout,
BranchKeys.FastForward,
BranchKeys.Push,
BranchKeys.ForcePush,
BranchKeys.New,
BranchKeys.Delete,
BranchKeys.ViewPRs,
Expand All @@ -73,6 +79,8 @@ func rebindBranchKeys(keys []config.Keybinding) error {
key = &BranchKeys.Delete
case "push":
key = &BranchKeys.Push
case "forcePush":
key = &BranchKeys.ForcePush
case "fastForward":
key = &BranchKeys.FastForward
case "checkout":
Expand Down
Loading