Skip to content
Merged
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
120 changes: 48 additions & 72 deletions internal/tui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,35 +657,28 @@ func (m *Model) handleFilesPanelKeys(msg tea.KeyMsg) tea.Cmd {
}

case key.Matches(msg, keys.StageItem):
return tea.Batch(
func() tea.Msg {
var cmdStr string
var err error
if status[0] == ' ' || status[0] == '?' {
_, cmdStr, err = m.git.AddFiles([]string{filePath})
} else {
_, cmdStr, err = m.git.ResetFiles([]string{filePath})
}
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
},
m.fetchPanelContent(FilesPanel),
m.fetchPanelContent(StatusPanel),
)
return func() tea.Msg {
var cmdStr string
var err error
if status[0] == ' ' || status[0] == '?' {
_, cmdStr, err = m.git.AddFiles([]string{filePath})
} else {
_, cmdStr, err = m.git.ResetFiles([]string{filePath})
}
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
}

case key.Matches(msg, keys.StageAll):
return tea.Batch(
func() tea.Msg {
_, cmdStr, err := m.git.AddFiles([]string{"."})
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
},
m.fetchPanelContent(FilesPanel),
)
return func() tea.Msg {
_, cmdStr, err := m.git.AddFiles([]string{"."})
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
}

case key.Matches(msg, keys.Discard):
m.mode = modeConfirm
Expand All @@ -708,17 +701,13 @@ func (m *Model) handleFilesPanelKeys(msg tea.KeyMsg) tea.Cmd {
}

case key.Matches(msg, keys.StashAll):
return tea.Batch(
func() tea.Msg {
_, cmdStr, err := m.git.StashAll()
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
},
m.fetchPanelContent(FilesPanel),
m.fetchPanelContent(StashPanel),
)
return func() tea.Msg {
_, cmdStr, err := m.git.StashAll()
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
}
}
return nil
}
Expand All @@ -740,18 +729,13 @@ func (m *Model) handleBranchesPanelKeys(msg tea.KeyMsg) tea.Cmd {

switch {
case key.Matches(msg, keys.Checkout):
return tea.Batch(
func() tea.Msg {
_, cmdStr, err := m.git.Checkout(branchName)
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
},
m.fetchPanelContent(StatusPanel),
m.fetchPanelContent(BranchesPanel),
m.fetchPanelContent(CommitsPanel),
)
return func() tea.Msg {
_, cmdStr, err := m.git.Checkout(branchName)
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
}

case key.Matches(msg, keys.NewBranch):
m.mode = modeInput
Expand Down Expand Up @@ -909,30 +893,22 @@ func (m *Model) handleStashPanelKeys(msg tea.KeyMsg) tea.Cmd {

switch {
case key.Matches(msg, keys.StashApply):
return tea.Batch(
func() tea.Msg {
_, cmdStr, err := m.git.Stash(git.StashOptions{Apply: true, StashID: stashID})
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
},
m.fetchPanelContent(FilesPanel),
m.fetchPanelContent(StashPanel),
)
return func() tea.Msg {
_, cmdStr, err := m.git.Stash(git.StashOptions{Apply: true, StashID: stashID})
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
}

case key.Matches(msg, keys.StashPop):
return tea.Batch(
func() tea.Msg {
_, cmdStr, err := m.git.Stash(git.StashOptions{Pop: true, StashID: stashID})
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
},
m.fetchPanelContent(FilesPanel),
m.fetchPanelContent(StashPanel),
)
return func() tea.Msg {
_, cmdStr, err := m.git.Stash(git.StashOptions{Pop: true, StashID: stashID})
if err != nil {
return errMsg{err}
}
return commandExecutedMsg{cmdStr}
}

case key.Matches(msg, keys.StashDrop):
m.mode = modeConfirm
Expand Down