-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(branches): delete branch with prompt (#430)
* feat(branches): delete branch with confirmation * fix: remove log
- Loading branch information
Showing
3 changed files
with
74 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
package reposection | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
gitm "github.com/aymanbagabas/git-module" | ||
tea "github.com/charmbracelet/bubbletea" | ||
|
||
"github.com/dlvhdr/gh-dash/v4/git" | ||
"github.com/dlvhdr/gh-dash/v4/ui/constants" | ||
"github.com/dlvhdr/gh-dash/v4/ui/context" | ||
) | ||
|
||
func (m *Model) delete() (tea.Cmd, error) { | ||
b := m.getCurrBranch() | ||
|
||
taskId := fmt.Sprintf("delete_%s_%d", b.Data.Name, time.Now().Unix()) | ||
task := context.Task{ | ||
Id: taskId, | ||
StartText: fmt.Sprintf("Deleting branch %s", b.Data.Name), | ||
FinishedText: fmt.Sprintf("Branch %s has been deleted", b.Data.Name), | ||
State: context.TaskStart, | ||
Error: nil, | ||
} | ||
startCmd := m.Ctx.StartTask(task) | ||
return tea.Batch(startCmd, func() tea.Msg { | ||
err := gitm.DeleteBranch(*m.Ctx.RepoPath, b.Data.Name, gitm.DeleteBranchOptions{Force: true}) | ||
if err != nil { | ||
return constants.TaskFinishedMsg{TaskId: taskId, Err: err} | ||
} | ||
repo, err := git.GetRepo(*m.Ctx.RepoPath) | ||
if err != nil { | ||
return constants.TaskFinishedMsg{TaskId: taskId, Err: err} | ||
} | ||
|
||
return constants.TaskFinishedMsg{ | ||
SectionId: 0, | ||
SectionType: SectionType, | ||
TaskId: taskId, | ||
Msg: repoMsg{repo: repo}, | ||
Err: err, | ||
} | ||
}), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters