Skip to content
Merged
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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down
15 changes: 15 additions & 0 deletions internal/git/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ func (g *GitCommands) Revert(commitHash string) (string, error) {

return string(output), nil
}

// ResetToCommit resets the current HEAD to the specified commit.
func (g *GitCommands) ResetToCommit(commitHash string) (string, error) {
if commitHash == "" {
return "", fmt.Errorf("commit hash is required")
}

cmd := exec.Command("git", "reset", "--hard", commitHash)
output, err := cmd.CombinedOutput()
if err != nil {
return string(output), fmt.Errorf("failed to reset to commit: %v", err)
}

return string(output), nil
}
10 changes: 10 additions & 0 deletions internal/git/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,13 @@ func (g *GitCommands) Stash(options StashOptions) (string, error) {

return string(output), nil
}

// StashAll stashes all changes, including untracked files.
func (g *GitCommands) StashAll() (string, error) {
cmd := exec.Command("git", "stash", "push", "-u", "-m", "gitx auto stash")
output, err := cmd.CombinedOutput()
if err != nil {
return string(output), fmt.Errorf("failed to stash all changes: %v", err)
}
return string(output), nil
}
9 changes: 2 additions & 7 deletions internal/tui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type KeyMap struct {
StageItem key.Binding
StageAll key.Binding
Discard key.Binding
Reset key.Binding
Stash key.Binding
StashAll key.Binding
Commit key.Binding
Expand Down Expand Up @@ -73,7 +72,7 @@ func (k KeyMap) FullHelp() []HelpSection {
Title: "Files",
Bindings: []key.Binding{
k.Commit, k.Stash, k.StashAll, k.StageItem,
k.StageAll, k.Discard, k.Reset,
k.StageAll, k.Discard,
},
},
{
Expand Down Expand Up @@ -211,17 +210,13 @@ func DefaultKeyMap() KeyMap {
key.WithKeys("d"),
key.WithHelp("d", "Discard"),
),
Reset: key.NewBinding(
key.WithKeys("D"),
key.WithHelp("D", "Reset"),
),
Stash: key.NewBinding(
key.WithKeys("s"),
key.WithHelp("s", "Stash"),
),
StashAll: key.NewBinding(
key.WithKeys("S"),
key.WithHelp("S", "Stage all"),
key.WithHelp("S", "Stash all"),
),
Commit: key.NewBinding(
key.WithKeys("c"),
Expand Down
24 changes: 17 additions & 7 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tui
import (
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand All @@ -16,6 +17,7 @@ const (
modeNormal appMode = iota
modeInput
modeConfirm
modeCommit
)

// Model represents the state of the TUI.
Expand All @@ -37,12 +39,14 @@ type Model struct {
repoName string
branchName string
// New fields for pop-ups
mode appMode
promptTitle string
confirmMessage string
textInput textinput.Model
inputCallback func(string) tea.Cmd
confirmCallback func(bool) tea.Cmd
mode appMode
promptTitle string
confirmMessage string
textInput textinput.Model
descriptionInput textarea.Model
inputCallback func(string) tea.Cmd
commitCallback func(title, description string) tea.Cmd
confirmCallback func(bool) tea.Cmd
}

// initialModel creates the initial state of the application.
Expand All @@ -65,7 +69,12 @@ func initialModel() Model {
ti := textinput.New()
ti.Focus()
ti.CharLimit = 256
ti.Width = 50
ti.Width = 80

ta := textarea.New()
ta.Placeholder = "Enter commit description"
ta.SetWidth(80)
ta.SetHeight(5)

return Model{
theme: Themes[themeNames[0]],
Expand All @@ -82,6 +91,7 @@ func initialModel() Model {
panels: panels,
mode: modeNormal,
textInput: ti,
descriptionInput: ta,
}
}

Expand Down
Loading