Skip to content
Open
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
13 changes: 9 additions & 4 deletions pkg/commands/git_commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ func (self *StatusCommands) IsBareRepo() bool {
}

func (self *StatusCommands) IsInRebase() (bool, error) {
exists, err := self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge"))
if err == nil && exists {
return true, nil
for _, file := range []string{"rebase-merge/head-name", "rebase-apply/head-name", "REBASE_HEAD"} {
exists, err := self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), file))
if err != nil {
return false, err
}
if exists {
return true, nil
}
}
return self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-apply"))
return false, nil
}

// IsInMergeState states whether we are still mid-merge
Expand Down
77 changes: 77 additions & 0 deletions pkg/commands/git_commands/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package git_commands

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestStatusCommandsIsInRebase(t *testing.T) {
type scenario struct {
testName string
prepare func(t *testing.T, gitDir string)
expected bool
}

scenarios := []scenario{
{
testName: "returns true when rebase-merge/head-name exists",
prepare: func(t *testing.T, gitDir string) {
assert.NoError(t, writeFile(filepath.Join(gitDir, "rebase-merge", "head-name"), "refs/heads/main\n"))
},
expected: true,
},
{
testName: "returns true when rebase-apply/head-name exists",
prepare: func(t *testing.T, gitDir string) {
assert.NoError(t, writeFile(filepath.Join(gitDir, "rebase-apply", "head-name"), "refs/heads/main\n"))
},
expected: true,
},
{
testName: "returns true when REBASE_HEAD exists",
prepare: func(t *testing.T, gitDir string) {
assert.NoError(t, writeFile(filepath.Join(gitDir, "REBASE_HEAD"), "abc123\n"))
},
expected: true,
},
{
testName: "returns false when rebase directory is stale without markers",
prepare: func(t *testing.T, gitDir string) {
assert.NoError(t, createDir(filepath.Join(gitDir, "rebase-merge")))
},
expected: false,
},
}

for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
repoPath := t.TempDir()
gitDir := filepath.Join(repoPath, ".git")
if !assert.NoError(t, createDir(gitDir)) {
return
}
s.prepare(t, gitDir)

status := NewStatusCommands(buildGitCommon(commonDeps{repoPaths: MockRepoPaths(repoPath)}))
actual, err := status.IsInRebase()
if !assert.NoError(t, err) {
return
}
assert.Equal(t, s.expected, actual)
})
}
}

func writeFile(path string, contents string) error {
if err := createDir(filepath.Dir(path)); err != nil {
return err
}
return os.WriteFile(path, []byte(contents), 0o644)
}

func createDir(path string) error {
return os.MkdirAll(path, 0o755)
}
15 changes: 11 additions & 4 deletions pkg/gui/pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ func (gui *Gui) desiredPtySize(view *gocui.View) *pty.Winsize {

func (gui *Gui) onResize() error {
gui.Mutexes.PtyMutex.Lock()
defer gui.Mutexes.PtyMutex.Unlock()
hasPtyViews := len(gui.viewPtmxMap) > 0

for viewName, ptmx := range gui.viewPtmxMap {
// TODO: handle resizing properly: we need to actually clear the main view
// and re-read the output from our pty. Or we could just re-run the original
// command from scratch
// Resize any active ptys first so they match the new view dimensions.
view, _ := gui.g.View(viewName)
if err := pty.Setsize(ptmx, gui.desiredPtySize(view)); err != nil {
gui.Mutexes.PtyMutex.Unlock()
return utils.WrapError(err)
}
}

gui.Mutexes.PtyMutex.Unlock()

if hasPtyViews {
// Custom pagers can render based on width. Re-running the current side's main
// render after a resize ensures the diff output is regenerated for the new size.
gui.c.Context().CurrentSide().HandleRenderToMain()
}

return nil
}

Expand Down